ALMaSS  1.0
The Animal, Landscape and Man Simulation System
Partridge_Covey Class Reference

The collective for a family of partridges
More...

#include <Partridge_Covey.h>

Inheritance diagram for Partridge_Covey:
TAnimal TALMaSSObject

Public Member Functions

bool NestFindSlow (int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
 Find nest location (wrap around) More...
 
bool CoveyEmigrate ()
 Test for covey emigration. More...
 
void CoveyIndividualEmigrate ()
 Test for individuals from covey emigrating. More...
 
bool TooClose ()
 Test for another covey too close. More...
 
bool HaveWeChicks (void)
 Check if covey contains chicks. More...
 
int GetUncleNumber ()
 Returns the number of uncles. More...
 
int GetmaxAllowedMove ()
 Return the max possible move distance today. More...
 
double GetmaxFoodNeedToday ()
 Return the maximum food need today. More...
 
void OnAddChick (Partridge_Female *a_pf)
 Add a chick. More...
 
void OnChickDeath ()
 Remove a dead chick. More...
 
void OnChickMature ()
 Remove a matured chick. More...
 
void ChickExtraMortality ()
 Apply extra chick mortality. More...
 
void SetCoveyDissolveDate (int date)
 Set the dissolve date. More...
 
Partridge_FemaleFindMeAMateInCovey (int a_family_counter)
 Is their a suitable female mate in the covey? More...
 
Partridge_FemaleGetUnpairedFemale ()
 Finds the first unpaired female in the covey. More...
 
Partridge_FemaleGetUnpairedFemale_virgin ()
 Finds the first never paired female in the covey. More...
 
Partridge_MaleGetMaleInCovey ()
 Find a male in the covey. More...
 
Partridge_BaseGetMember (int a_member)
 Returns pointer to a_member. More...
 
Partridge_BaseGetAMember ()
 Returns a random member. More...
 
Partridge_CoveyFindNeighbour ()
 Finds the closest other covey. More...
 
void OnDissolve (int date)
 Dissolve message handler. More...
 
bool AllFlocking ()
 Debug method. More...
 
bool AllFlocking2 ()
 Debug method. More...
 
bool ArePaired ()
 Debug method. More...
 
void SanityCheck ()
 Debug method. More...
 
void SanityCheck3 ()
 Debug method. More...
 
void SanityCheck4 ()
 Debug method. More...
 
void SanityCheck2 (int no_chicks)
 Debug method. More...
 
void RemoveExtraChick ()
 Decrement the chick number. More...
 
int GetOurChicks ()
 Return the number of chicks. More...
 
unsigned int GetCoveySize ()
 Return the covey size. More...
 
void SetChickAge (int age)
 Set chick age. More...
 
int GetChickAge ()
 Return chick age. More...
 
bool CanWeMerge (int a_NoUncles)
 Merging test. More...
 
bool ManagerCheckMerge (int a_noOfUncles)
 Merging test for uncle number. More...
 
void SetUncle ()
 Swap uncle to alhpha. More...
 
void KillExcessChicks (int remaining)
 Kill extra chicks. More...
 
void ActOnParentDeath ()
 Determine the chick mortality on parent death. More...
 
bool NestFindLocation (void)
 Try to locate a suitable nesting location. More...
 
bool NestOnNest (void)
 Are we nesting? More...
 
void NestLeave (void)
 Leave the nest
More...
 
int NestGetX (void)
 Return nest x-coord. More...
 
int NestGetY (void)
 Return nest y-coord. More...
 
double SupplyFoodToday (void)
 Return the food obtained today. More...
 
double SupplyDistanceMoved (void)
 Return the distance moved today. More...
 
double AssessHabitatQuality (int &a_sz)
 Assess habitat quality (with checks) More...
 
double AssessHabitatQualityFaster ()
 Assess habitat quality (efficient) More...
 
int AssessGetSize (void)
 Get the size ('radius') used during territory evaluation. More...
 
void FixHabitat (void)
 Accept this breeding location. More...
 
double SupplyHabitatQuality ()
 Return habitat quality at our location. More...
 
void SetFixed (bool a_is_fixed)
 Prevent/enable peg drift. More...
 
bool IsFixed (void)
 Wonder whether the peg is fixed? More...
 
Partridge_Object GetObjectType (void)
 Return object type. More...
 
void MoveDistance (int a_max_distance, int a_step_size, double a_food_density_needed)
 Entry point for movement. More...
 
int MoveCanMove (int a_x, int a_y)
 Test of movement step. More...
 
bool FlyTo (int a_distance)
 Fly to
More...
 
void MoveTo (int a_x, int a_y)
 unused More...
 
Partridge_MaleFindMeAHusband (Partridge_Female *a_female)
 Find mate in covey. More...
 
Partridge_FemaleFindMeAWife (Partridge_Male *a_male)
 Find mate in covey. More...
 
Partridge_BaseGetUncle ()
 Find uncle in covey. More...
 
Partridge_FemaleFindMateInArea (int a_max_distance)
 Find mate in area. More...
 
void BeginStep (void)
 Covey BeginStep. More...
 
void Step (void)
 Covey Step. More...
 
void EndStep (void)
 Covey EndStep. More...
 
void AddMember (Partridge_Base *a_new_member)
 
More...
 
bool IsMember (Partridge_Base *a_possible_member)
 
More...
 
int RemoveMember (Partridge_Base *a_former_member)
 Remove a member from the covey. More...
 
unsigned int Memberships (void)
 Get covey size. More...
 
bool LifeEssenceLow (void)
 
More...
 
bool ForceLow (void)
 
More...
 
unsigned int X (void)
 
More...
 
unsigned int Y (void)
 
More...
 
unsigned int XCenter (void)
 
More...
 
unsigned int YCenter (void)
 
More...
 
double XCenterF (void)
 
More...
 
double YCenterF (void)
 
More...
 
unsigned int ID (void)
 
More...
 
void ManagerCheckMerge (void)
 
More...
 
void ManagerRethinkPos (void)
 
More...
 
void ManagerDriftPos (void)
 
More...
 
void ManagerUpdatePos (void)
 
More...
 
void ManagerSetPermanent (void)
 Unused
More...
 
bool ManagerIsPermanant (void)
 Unused
More...
 
 Partridge_Covey (Partridge_Base *a_first_member, Partridge_Population_Manager *a_manager, unsigned int a_center_x, unsigned int a_center_y, Landscape *a_map)
 Constructor. More...
 
virtual ~Partridge_Covey (void)
 Destructor. More...
 
- Public Member Functions inherited from TAnimal
unsigned SupplyFarmOwnerRef ()
 
AnimalPosition SupplyPosition ()
 
APoint SupplyPoint ()
 
int SupplyPolygonRef ()
 
int Supply_m_Location_x ()
 
int Supply_m_Location_y ()
 
virtual void KillThis ()
 
virtual void CopyMyself ()
 
void SetX (int a_x)
 
void SetY (int a_y)
 
 TAnimal (int x, int y, Landscape *L)
 
virtual void ReinitialiseObject (int x, int y, Landscape *L)
 Used to re-use an object - must be implemented in descendent classes. More...
 
virtual int WhatState ()
 
virtual void Dying ()
 
void CheckManagement (void)
 
void CheckManagementXY (int x, int y)
 
virtual bool OnFarmEvent (FarmToDo)
 
- Public Member Functions inherited from TALMaSSObject
int GetCurrentStateNo ()
 Returns the current state number. More...
 
void SetCurrentStateNo (int a_num)
 Sets the current state number. More...
 
bool GetStepDone ()
 Returns the step done indicator flag. More...
 
void SetStepDone (bool a_bool)
 Sets the step done indicator flag. More...
 
virtual void ReinitialiseObject ()
 Used to re-use an object - must be implemented in descendent classes. More...
 
 TALMaSSObject ()
 The constructor for TALMaSSObject. More...
 
virtual ~TALMaSSObject ()
 The destructor for TALMaSSObject. More...
 
void OnArrayBoundsError ()
 Used for debugging only, tests basic object properties. More...
 

Public Attributes

Partridge_Coveym_neighbourlist [50]
 List of coveys close to this covey. More...
 
int m_neighbourlist_size
 Number of coveys close to this covey. More...
 

Protected Member Functions

void CoveyUpdateMemberPositions (int a_x, int a_y)
 Update all covey members x,y coords. More...
 
bool NestGoodSpot (int a_x, int a_y)
 Evaluate x,y as a nest location. More...
 
bool NestFindFast (int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
 Find nest location. More...
 
int Norm (int a_coord, int a_size)
 Wrap-around utility function. More...
 
int NormInc (int a_coord, int a_size)
 Wrap-around utility function. More...
 
int NormDec (int a_coord, int a_size)
 Wrap-around utility function. More...
 
bool NestNearBadAreas (int a_x, int a__y)
 Test for proximity to unacceptable areas. More...
 
bool NestBadArea (int a_x, int a__y)
 Nest location evaluation function. More...
 
bool NestNearNests (int a_x, int a_y, int a_min_dist_sq)
 Nest location evaluation function. More...
 
bool NestBadAreasScanSlow (int a_min_x, int a_min_y, int a_length, int a_x, int a_y)
 Nest location evaluation function. More...
 
bool NestBadAreasScanFast (int a_min_x, int a_min_y, int a_length, int a_x, int a_y)
 Nest location evaluation function. More...
 
bool FlyToFast (int a_distance)
 Move a_distance from current covey position. More...
 
bool FlyToSlow (int a_distance)
 Move a_distance from current covey position (wraparound) More...
 
double Pressure (double a_distance)
 Get the pressure force. More...
 
bool PressureLimitExceeded (double a_pressure)
 Test for exceedence of pressure limit. More...
 
void DistanceUpdate (void)
 Updates distance to nearest covey. More...
 
void DistanceUpdate2 (void)
 Updates distance to fixed nearest covey. More...
 
double DistanceToCovey (Partridge_Covey *a_covey)
 Get distance too covey. More...
 
double HabitatEvaluate (int a_center_x, int a_center_y, int *a_size_used, bool a_rethink_size)
 Entry point for habitat evaluation. More...
 
double HabitatEvaluateFaster (int a_center_x, int a_center_y)
 Evaluate habitat fast. More...
 
double HabitatEvaluateFast (int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
 Evaluate habitat (wrap around) More...
 
double HabitatEvaluateSlow (int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
 
More...
 
double HabitatEvalPoly (TTypesOfLandscapeElement a_cet, int a_poly)
 
More...
 
int HabitatEvalPolyField (int a_field)
 Evaluate a field's habitat quality. More...
 
bool MoveTryExclude (int a_dist_sq)
 Uses the peg force to exclude possible movement directions. More...
 
bool MoveTryExcludeHarder (int a_dist_sq)
 Uses the peg force to exclude possible movement directions. More...
 
void MoveDirectionsAllowed (int a_x, int a_y)
 Test possible movement directions. More...
 
void MoveOptimalDirectionSlow (int a_x, int a_y)
 Choose best foraging direction. More...
 
void MoveOptimalDirectionFast (int a_x, int a_y)
 Choose best foraging direction (wrap around) More...
 
int MoveWeighDirection (int a_x, int a_y)
 Weighted foraging walk. More...
 
void MoveQualMemory (int a_qual)
 Make a move based on memory of quality. More...
 
double MoveDoIt (int *a_x, int *a_y, int a_dir, int a_step_size)
 We know where we want to go. Now do it! More...
 
int MoveCanMove (TTypesOfLandscapeElement a_ele)
 Test if we can go there. More...
 
double MoveMagicVegToFood (int a_polygon)
 Move optimising food intake. More...
 
int MoveEvalEdgesAndQual (int a_edges, double a_qual)
 Move evaluation taking edges into account. More...
 
int MoveSelectFuzzy (void)
 Fuzzdy movement selection. More...
 
bool MoveSelectLimit (int a_limit, int a_x, int a_y)
 Part of movement evaluation. More...
 
int MoveSelect (void)
 Part of movement evaluation. More...
 
void MoveVegConstInit (void)
 Part of movement evaluation. More...
 
void OntheDadDead ()
 Behaviour when alpha male is killed. More...
 
void OntheMumDead ()
 Behaviour when alpha female is killed. More...
 
void KillChicks (int percent)
 Kill a proportion of the chicks. More...
 
int SupplyChickAge (void)
 Returns the age of the chicks. More...
 
- Protected Member Functions inherited from TAnimal
void CorrectWrapRound ()
 Corrects wrap around co-ordinate problems. More...
 

Protected Attributes

int m_flyto_steps
 costly intermediate variable More...
 
int m_flyto_dist
 costly intermediate variable More...
 
double m_flyto_ts
 costly intermediate variable More...
 
bool m_essence_low
 flag for excess density - unused More...
 
bool m_peg_is_fixed
 flag for fixed homerange More...
 
bool m_permanent_marker
 Unused
More...
 
unsigned int m_id
 Unique ID no-
More...
 
Partridge_Basem_members [100]
 List of covey members
More...
 
unsigned int m_members_size
 Size of covey
More...
 
bool m_step_done
 Signals Step is done for today
More...
 
bool m_dist_done
 Signals distance updating is done for today
More...
 
double m_nearest_covey_dist
 Closest covey distance
More...
 
bool m_terr_done
 Signals homerange evaluation done
More...
 
double m_terr_qual
 Homerange evaluation score
More...
 
bool m_force_low
 unused
More...
 
Partridge_State m_state
 The current behavioural state. More...
 
Landscapem_map
 A pointer to the landscape. More...
 
int m_width
 Landscape width. More...
 
int m_height
 Landscape height. More...
 
Partridge_Population_Managerm_manager
 Covey's population manager. More...
 
double m_center_x_float
 Covey centre as float. More...
 
double m_center_y_float
 Covey centre as float. More...
 
double m_new_center_x_float
 Covey centre as float. More...
 
double m_new_center_y_float
 Covey centre as float. More...
 
int m_center_x
 Covey centre. More...
 
int m_center_y
 Covey centre. More...
 
int m_covey_x
 Covey x-coord. More...
 
int m_covey_y
 Covey y-coord. More...
 
int m_terr_size
 Homerange width. More...
 
bool m_nest_on_nest
 Nesting flag. More...
 
int m_nest_x
 Nest coord-x. More...
 
int m_nest_y
 Nest coord-y. More...
 
bool m_assess_done
 Have assessed habitat quality? More...
 
double m_assess_qual
 Habitat quality. More...
 
bool m_move_done
 Have moved? More...
 
double m_dist_moved
 Distance moved. More...
 
double m_food_today
 Food collected. More...
 
int m_assess_size
 Current homerange assessment radius. More...
 
int m_move_get_index
 Internal variable. More...
 
int m_move_get_size
 Internal variable. More...
 
int m_move_qual_memory [4]
 Steps remembered. More...
 
int m_move_qual_hist [4][MOVE_QUAL_HIST_SIZE]
 Internal variable. More...
 
int m_move_whence_we_came
 Internal variable. More...
 
int m_move_step_size
 Internal variable. More...
 
double m_move_step_size_inv
 Internal variable. More...
 
Partridge_Femalem_theMum
 Pointer to the alpha male. More...
 
Partridge_Malem_theDad
 Pointer to the alpha female. More...
 
int m_ourChicks
 No chicks in covey. More...
 
int m_CoveyDissolveDate
 Date for covey dissolve. More...
 
int m_maxAllowedMove
 Max move distance today. More...
 
double m_maxFoodNeedToday
 Food needed today. More...
 
int m_ChickAge
 Age of chicks. More...
 
- Protected Attributes inherited from TAnimal
int m_Location_x
 
int m_Location_y
 
Landscapem_OurLandscape
 
- Protected Attributes inherited from TALMaSSObject
int m_CurrentStateNo
 The basic state number for all objects - '-1' indicates death. More...
 
bool m_StepDone
 Indicates whether the iterative step code is done for this timestep. More...
 

Detailed Description

The collective for a family of partridges

The partridge covey is contains all behaviour that is performed as a group of birds. In fact this group can be as small as 1 bird, but if the behaviour is the same as a family group it will appear here.
Note that the covey is treated just like a life-stage, and is handled by the Partridge_Population_Manager.

Each covey has a 'peg' position, which starts out as the center of a newly established territory. It also has a covey location, which may or may not coincide with the peg position. The covey can move some distance away from the peg, given by an 'elastic' function of distance between covey (physical) and the virtual territory center 'peg'. If a partridge would like to assess the quality of a hypothetial territory centeret at its current (covey) position, it will call Partridge_Covey::AssessHabitatQuality and make decisions on suitability depending on the value returned. The size of the potential territory evaluated is the minimum of the distance to the closest neighbour peg and a configurable maximum territory radius, Partridge_All.cpp::cfg_par_terr_max_width.

Constructor & Destructor Documentation

◆ Partridge_Covey()

Partridge_Covey::Partridge_Covey ( Partridge_Base a_first_member,
Partridge_Population_Manager a_manager,
unsigned int  a_center_x,
unsigned int  a_center_y,
Landscape a_map 
)

Constructor.

1978  : TAnimal( a_center_x, a_center_y, a_map ) {
1980  m_map = a_map;
1981  m_width = a_map->SupplySimAreaWidth();
1982  m_height = a_map->SupplySimAreaHeight();
1983 
1984  m_maxAllowedMove = 1000; // default values
1985  m_maxFoodNeedToday = 10000; // default values
1986 
1987  m_manager = a_manager;
1988  m_center_x = a_center_x;
1989  m_center_y = a_center_y;
1990  m_center_x_float = ( double )m_center_x;
1991  m_center_y_float = ( double )m_center_y;
1992  m_covey_x = a_center_x;
1993  m_covey_y = a_center_y;
1994 
1995  m_nest_on_nest = false, m_nest_x = m_center_x; // Shouldn't matter.
1996  m_nest_y = m_center_y; // "
1997 
1998  m_step_done = false;
1999  m_permanent_marker = false;
2000  m_move_done = false;
2001  m_dist_moved = 0.0; // Shouldn't matter.
2002  m_food_today = 0.0; // "
2003  m_flyto_dist = -1;
2004 
2005  m_assess_done = false;
2006  //m_assess_qual = 0.0; // Shouldn't matter.
2007  m_assess_size = 0;
2008 
2009  m_terr_done = false;
2010  //m_terr_qual = 0.0; // Shouldn't matter.
2011  // Actually this matters if we start moving before
2012  // choosing a territory.
2014 
2015  m_dist_done = false;
2016  m_nearest_covey_dist = sqrt( ( double )m_width * m_height );
2017  m_peg_is_fixed = false;
2018  m_essence_low = false;
2019  m_force_low = true;
2020 
2021  //m_move_get_enable = false;
2022 
2023  /* m_members.resize( 1 ); */
2024  if ( a_first_member ) {
2025  m_members_size = 1;
2026  m_members[ 0 ] = a_first_member;
2027  } else {
2028  m_members_size = 0;
2029  }
2030 
2031  for ( int i = 0; i < MOVE_QUAL_HIST_SIZE; i++ ) {
2032  m_move_qual_hist[ 0 ] [ i ] = 0;
2033  m_move_qual_hist[ 1 ] [ i ] = 0;
2034  m_move_qual_hist[ 2 ] [ i ] = 0;
2035  m_move_qual_hist[ 3 ] [ i ] = 0;
2036  }
2037 
2038  m_move_qual_memory[ 0 ] = 0;
2039  m_move_qual_memory[ 1 ] = 0;
2040  m_move_qual_memory[ 2 ] = 0;
2041  m_move_qual_memory[ 3 ] = 0;
2042 
2043  MoveVegConstInit();
2044  CoveyUpdateMemberPositions( a_center_x, a_center_y );
2045 
2046  if ( g_covey_manager == NULL ) {
2048  }
2049  g_covey_manager->AddCovey( this );
2050 
2051  if ( a_manager )
2052  a_manager->AddObject( pob_Covey, this );
2053 
2056  m_move_step_size = 1;
2057  m_move_step_size_inv = 1.0;
2058  m_CoveyDissolveDate = -1; // never do it
2059  m_ourChicks = 0; // don't start with chicks or parents
2060  m_theDad = NULL;
2061  m_theMum = NULL;
2062 }
int random(int a_range)
Definition: ALMaSS_CmdLine.cpp:142
@ pars_CoveyBeing
Definition: Partridge_All.h:285
@ pob_Covey
Definition: Partridge_All.h:297
class CoveyManager * g_covey_manager
Definition: Partridge_Covey.cpp:2070
CfgInt g_par_terr_max_width("PAR_TERR_MAX_WIDTH", CFG_CUSTOM, 500)
Limit to homerange radius.
static unsigned int g_covey_id_counter
Definition: Partridge_Covey.cpp:231
int value(void)
Definition: configurator.h:98
The covey manager class.
Definition: Partridge_Covey.h:792
void AddCovey(Partridge_Covey *a_covey)
Add a new covey.
Definition: Partridge_Covey.cpp:2222
int SupplySimAreaHeight(void)
Definition: landscape.h:1637
int SupplySimAreaWidth(void)
Definition: landscape.h:1632
bool m_peg_is_fixed
flag for fixed homerange
Definition: Partridge_Covey.h:102
int m_covey_y
Covey y-coord.
Definition: Partridge_Covey.h:148
bool m_permanent_marker
Unused
Definition: Partridge_Covey.h:104
double m_maxFoodNeedToday
Food needed today.
Definition: Partridge_Covey.h:395
int m_flyto_dist
costly intermediate variable
Definition: Partridge_Covey.h:96
Partridge_State m_state
The current behavioural state.
Definition: Partridge_Covey.h:124
bool m_dist_done
Signals distance updating is done for today
Definition: Partridge_Covey.h:114
bool m_assess_done
Have assessed habitat quality?
Definition: Partridge_Covey.h:158
double m_center_y_float
Covey centre as float.
Definition: Partridge_Covey.h:136
double m_food_today
Food collected.
Definition: Partridge_Covey.h:166
int m_height
Landscape height.
Definition: Partridge_Covey.h:130
double m_move_step_size_inv
Internal variable.
Definition: Partridge_Covey.h:320
int m_nest_x
Nest coord-x.
Definition: Partridge_Covey.h:154
bool m_terr_done
Signals homerange evaluation done
Definition: Partridge_Covey.h:118
int m_center_x
Covey centre.
Definition: Partridge_Covey.h:142
int m_ourChicks
No chicks in covey.
Definition: Partridge_Covey.h:381
Partridge_Male * m_theDad
Pointer to the alpha female.
Definition: Partridge_Covey.h:379
bool m_essence_low
flag for excess density - unused
Definition: Partridge_Covey.h:100
Partridge_Population_Manager * m_manager
Covey's population manager.
Definition: Partridge_Covey.h:132
unsigned int m_id
Unique ID no-
Definition: Partridge_Covey.h:106
int m_move_whence_we_came
Internal variable.
Definition: Partridge_Covey.h:316
int m_maxAllowedMove
Max move distance today.
Definition: Partridge_Covey.h:390
double m_dist_moved
Distance moved.
Definition: Partridge_Covey.h:164
int m_covey_x
Covey x-coord.
Definition: Partridge_Covey.h:146
int m_terr_size
Homerange width.
Definition: Partridge_Covey.h:150
int m_move_qual_memory[4]
Steps remembered.
Definition: Partridge_Covey.h:308
double m_nearest_covey_dist
Closest covey distance
Definition: Partridge_Covey.h:116
double m_center_x_float
Covey centre as float.
Definition: Partridge_Covey.h:134
Landscape * m_map
A pointer to the landscape.
Definition: Partridge_Covey.h:126
int m_width
Landscape width.
Definition: Partridge_Covey.h:128
bool m_nest_on_nest
Nesting flag.
Definition: Partridge_Covey.h:152
int m_CoveyDissolveDate
Date for covey dissolve.
Definition: Partridge_Covey.h:383
void CoveyUpdateMemberPositions(int a_x, int a_y)
Update all covey members x,y coords.
Definition: Partridge_Covey.cpp:1093
Partridge_Base * m_members[100]
List of covey members
Definition: Partridge_Covey.h:108
int m_center_y
Covey centre.
Definition: Partridge_Covey.h:144
void MoveVegConstInit(void)
Part of movement evaluation.
Definition: Partridge_Covey.cpp:3304
int m_move_step_size
Internal variable.
Definition: Partridge_Covey.h:318
bool m_step_done
Signals Step is done for today
Definition: Partridge_Covey.h:112
int m_assess_size
Current homerange assessment radius.
Definition: Partridge_Covey.h:296
int m_nest_y
Nest coord-y.
Definition: Partridge_Covey.h:156
Partridge_Female * m_theMum
Pointer to the alpha male.
Definition: Partridge_Covey.h:377
bool m_force_low
unused
Definition: Partridge_Covey.h:122
unsigned int m_members_size
Size of covey
Definition: Partridge_Covey.h:110
int m_move_qual_hist[4][MOVE_QUAL_HIST_SIZE]
Internal variable.
Definition: Partridge_Covey.h:310
bool m_move_done
Have moved?
Definition: Partridge_Covey.h:162
void AddObject(int ob_type, TAnimal *pTAo)
Definition: Partridge_Population_Manager.cpp:457
TAnimal(int x, int y, Landscape *L)
Definition: PopulationManager.cpp:1367

References CoveyManager::AddCovey(), Partridge_Population_Manager::AddObject(), CoveyUpdateMemberPositions(), g_covey_id_counter, g_covey_manager, g_par_terr_max_width, m_assess_done, m_assess_size, m_center_x, m_center_x_float, m_center_y, m_center_y_float, m_covey_x, m_covey_y, m_CoveyDissolveDate, m_dist_done, m_dist_moved, m_essence_low, m_flyto_dist, m_food_today, m_force_low, m_height, m_id, m_manager, m_map, m_maxAllowedMove, m_maxFoodNeedToday, m_members, m_members_size, m_move_done, m_move_qual_hist, m_move_qual_memory, m_move_step_size, m_move_step_size_inv, m_move_whence_we_came, m_nearest_covey_dist, m_nest_on_nest, m_nest_x, m_nest_y, m_ourChicks, m_peg_is_fixed, m_permanent_marker, m_state, m_step_done, m_terr_done, m_terr_size, m_theDad, m_theMum, m_width, MoveVegConstInit(), pars_CoveyBeing, pob_Covey, random(), Landscape::SupplySimAreaHeight(), Landscape::SupplySimAreaWidth(), and CfgInt::value().

◆ ~Partridge_Covey()

Partridge_Covey::~Partridge_Covey ( void  )
virtual

Destructor.

1971  {
1972  g_covey_manager->DelCovey( this );
1973 }
bool DelCovey(Partridge_Covey *a_covey)
Remove a covey.
Definition: Partridge_Covey.cpp:2230

References CoveyManager::DelCovey(), and g_covey_manager.

Member Function Documentation

◆ ActOnParentDeath()

void Partridge_Covey::ActOnParentDeath ( void  )

Determine the chick mortality on parent death.

Determines the probability of mortality following the death of a parent. This will depend on the age of the chicks and whether it is one or both parents that die and whether there are aunts or uncles present.

If we need to use aunts and uncles or if there is only one parent left then we assume only 8 chicks max can be brooded. The rest die, and the 8 are subject to a mortality probability.

2516  {
2517  int age = SupplyChickAge(); // depends on the fact that only one set of chicks
2518  if ( age >= cfg_par_parentdead_age2.value() ) return; // Old enough to cope
2519  if ( ( !m_theMum ) && ( !m_theDad ) ) {
2520  // Both parents dead - so need to look for uncles
2521  if ( GetUncleNumber() > 0 ) { // Can use an uncle or aunt
2522  SetUncle();
2523  } else
2524  KillChicks( 100 );
2525  return;
2526  }
2527  // depends on the fact that only one set of chicks
2528  // can be in the covey at any one time.
2529  if ( age < cfg_par_parentdead_age1.value() ) {
2530  KillExcessChicks( 8 ); // removes any chicks in excess of 8
2532  } else if ( age < cfg_par_parentdead_age2.value() )
2534 }
CfgInt cfg_par_parentdead_age1("PAR_PARENTDEAD_AGEONE", CFG_CUSTOM, 35)
Mortalty chance on parent death, young.
CfgInt cfg_par_parentdead_age2("PAR_PARENTDEAD_AGETWO", CFG_CUSTOM, 63)
Mortalty chance on parent death, older.
CfgInt cfg_par_parentdead_mort("PAR_PARENTDEAD_MORT", CFG_CUSTOM, 100)
Mortalty chance on parent death.
int GetUncleNumber()
Returns the number of uncles.
Definition: Partridge_Covey.cpp:2560
void KillChicks(int percent)
Kill a proportion of the chicks.
Definition: Partridge_Covey.cpp:2595
int SupplyChickAge(void)
Returns the age of the chicks.
Definition: Partridge_Covey.cpp:2608
void KillExcessChicks(int remaining)
Kill extra chicks.
Definition: Partridge_Covey.cpp:2573
void SetUncle()
Swap uncle to alhpha.
Definition: Partridge_Covey.cpp:2540

References cfg_par_parentdead_age1, cfg_par_parentdead_age2, cfg_par_parentdead_mort, GetUncleNumber(), KillChicks(), KillExcessChicks(), m_theDad, m_theMum, SetUncle(), SupplyChickAge(), and CfgInt::value().

Referenced by OntheDadDead(), and OntheMumDead().

◆ AddMember()

void Partridge_Covey::AddMember ( Partridge_Base a_new_member)


1644  {
1645  if ( m_CurrentStateNo == -1 ) {
1646  g_msg->Warn( WARN_BUG, "Partridge_Covey::AddMember(): ""Attempting to add a member to non-existent flock!", "" );
1647  exit( 1 );
1648  }
1649  if ( IsMember( a_new_member ) ) {
1650  g_msg->Warn( WARN_BUG, "Partridge_Covey::AddMember(): ""Attempting to add a member already belonging to the flock!", "" );
1651  exit( 1 );
1652  }
1653  if ( m_members_size>=99 ) {
1654  g_msg->Warn( WARN_BUG, "Partridge_Covey::AddMember(): ""Covey too big!", "" );
1655  exit( 1 );
1656  }
1657  //m_members.resize( m_members.size() + 1 );
1658  m_members_size++;
1659  m_members[ m_members_size - 1 ] = a_new_member;
1660 }
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
bool IsMember(Partridge_Base *a_possible_member)
Definition: Partridge_Covey.cpp:1709
int m_CurrentStateNo
The basic state number for all objects - '-1' indicates death.
Definition: PopulationManager.h:116
class MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41
@ WARN_BUG
Definition: maperrormsg.h:34

References g_msg, IsMember(), TALMaSSObject::m_CurrentStateNo, m_members, m_members_size, MapErrorMsg::Warn(), and WARN_BUG.

Referenced by ManagerCheckMerge(), Partridge_Base::Partridge_Base(), and Partridge_Base::SwitchCovey().

◆ AllFlocking()

bool Partridge_Covey::AllFlocking ( )

Debug method.

2362  {
2363  for ( unsigned i = 0; i < m_members_size; i++ ) {
2364  if ( ( m_members[ i ]->GetState() != pars_MFlocking ) && ( m_members[ i ]->GetState() != pars_FFlocking ) ) {
2365  return false;
2366  }
2367  }
2368  return true;
2369 }
@ pars_MFlocking
Definition: Partridge_All.h:279
@ pars_FFlocking
Definition: Partridge_All.h:282

References m_members, m_members_size, pars_FFlocking, and pars_MFlocking.

Referenced by CanWeMerge().

◆ AllFlocking2()

bool Partridge_Covey::AllFlocking2 ( )

Debug method.

2373  {
2374  for ( unsigned i = 0; i < m_members_size; i++ ) {
2375  if ( ( m_members[ i ]->GetState() != pars_MFlocking ) && ( m_members[ i ]->GetState() != pars_FFlocking ) ) {
2376  return false;
2377  }
2378  }
2379  return true;
2380 }

References m_members, m_members_size, pars_FFlocking, and pars_MFlocking.

Referenced by Partridge_Population_Manager::DissolveCovey().

◆ ArePaired()

bool Partridge_Covey::ArePaired ( )

Debug method.

2384  {
2385  Partridge_Male * MP;
2386  Partridge_Female * FP;
2387  for ( unsigned i = 0; i < m_members_size; i++ ) {
2388  if ( m_members[ i ]->GetObjectType() == pob_Male ) {
2389  MP = dynamic_cast < Partridge_Male * > ( m_members[ i ] );
2390  if ( MP->GetMate() )
2391  return false;
2392  } else if ( m_members[ i ]->GetObjectType() == pob_Female ) {
2393  FP = dynamic_cast < Partridge_Female * > ( m_members[ i ] );
2394  if ( FP->GetMate() )
2395  return false;
2396  }
2397  }
2398  return true;
2399 }
@ pob_Female
Definition: Partridge_All.h:297
@ pob_Male
Definition: Partridge_All.h:297
Partridge_Object GetObjectType(void)
Return object type.
Definition: Partridge_Covey.h:582
The partridge female class.
Definition: Partridge_All.h:770
Partridge_Male * GetMate(void)
Supply mate pointer.
Definition: Partridge_All.h:872
The partridge male class.
Definition: Partridge_All.h:657
Partridge_Female * GetMate(void)
Are we paired?
Definition: Partridge_All.h:719

References Partridge_Male::GetMate(), Partridge_Female::GetMate(), GetObjectType(), m_members, m_members_size, pob_Female, and pob_Male.

Referenced by CoveyIndividualEmigrate(), and Partridge_Population_Manager::DissolveCovey().

◆ AssessGetSize()

int Partridge_Covey::AssessGetSize ( void  )
inline

Get the size ('radius') used during territory evaluation.

554  {
555  return m_assess_size;
556  }

References m_assess_size.

◆ AssessHabitatQuality()

double Partridge_Covey::AssessHabitatQuality ( int &  a_sz)

Assess habitat quality (with checks)

1059  {
1060  if ( !m_assess_done ) {
1062  m_assess_done = true;
1063  }
1064  a_sz = m_assess_size;
1065  return m_assess_qual;
1066 }
double HabitatEvaluate(int a_center_x, int a_center_y, int *a_size_used, bool a_rethink_size)
Entry point for habitat evaluation.
Definition: Partridge_Covey.cpp:991
double m_assess_qual
Habitat quality.
Definition: Partridge_Covey.h:160

References HabitatEvaluate(), m_assess_done, m_assess_qual, m_assess_size, m_covey_x, and m_covey_y.

Referenced by FixHabitat().

◆ AssessHabitatQualityFaster()

double Partridge_Covey::AssessHabitatQualityFaster ( )

Assess habitat quality (efficient)

1068  {
1070  m_assess_done = true;
1071  return m_assess_qual;
1072 }
double HabitatEvaluateFaster(int a_center_x, int a_center_y)
Evaluate habitat fast.
Definition: Partridge_Covey.cpp:1027

References HabitatEvaluateFaster(), m_assess_done, m_assess_qual, m_covey_x, and m_covey_y.

Referenced by Partridge_Female::FFindingTerritory().

◆ BeginStep()

void Partridge_Covey::BeginStep ( void  )
virtual

Covey BeginStep.

Reimplemented from TAnimal.

1583  {
1584  if ( m_CurrentStateNo == -1 ) return;
1585  // Determine the movement distances and food requirements
1586  // Depends on the age of the chick
1587  //
1588  int age;
1589  // do we have any chicks?
1590  if ( GetOurChicks() > 0 ) {
1591  // if so then food requiremtns are dependent upon them
1592  age = m_ChickAge; // This set daily by the chicks
1593  }
1594  // otherwise then it is adult requirements
1596  m_maxFoodNeedToday = g_FoodNeed[ age ];
1597 
1598  if ( m_state == pars_CoveyDissolve ) {
1600  m_manager->DissolveCovey( this );
1602  m_CoveyDissolveDate = -1;
1603  }
1604  }
1605 }
@ pars_CoveyDissolve
Definition: Partridge_All.h:285
double g_FoodNeed[200]
Definition: Partridge_Population_Manager.cpp:65
CfgInt cfg_par_mature_threshold
int SupplyDayInYear(void)
Definition: landscape.h:1596
int GetOurChicks()
Return the number of chicks.
Definition: Partridge_Covey.h:471
int m_ChickAge
Age of chicks.
Definition: Partridge_Covey.h:397
void DissolveCovey(Partridge_Covey *a_covey)
Definition: Partridge_Population_Manager.cpp:1475
Landscape * m_OurLandscape
Definition: PopulationManager.h:229

References cfg_par_mature_threshold, Partridge_Population_Manager::DissolveCovey(), g_FoodNeed, GetOurChicks(), m_ChickAge, m_CoveyDissolveDate, TALMaSSObject::m_CurrentStateNo, m_manager, m_maxFoodNeedToday, TAnimal::m_OurLandscape, m_state, pars_CoveyBeing, pars_CoveyDissolve, Landscape::SupplyDayInYear(), and CfgInt::value().

◆ CanWeMerge()

bool Partridge_Covey::CanWeMerge ( int  a_NoUncles)

Merging test.

1833  {
1834  // The rules are that if we have no chicks then we can have up to 8 'uncles'
1835  // Otherwise only 4 are allowed.
1836  // The answer is no if we are still busy
1837  if ( !AllFlocking() ) return false;
1838  // Otherwise it depends on the number of uncles etc.
1839  int UncleNumber = GetUncleNumber();
1840  if ( m_ourChicks > 0 ) {
1841  if ( (UncleNumber + a_noOfUncles) > 4 ) return false;
1842  }
1843  else
1844  if ( m_map->SupplyDayInYear() < June ) {
1845  if ( (UncleNumber + a_noOfUncles) > 4 ) {
1846  return false;
1847  }
1848  } else if ( (UncleNumber + a_noOfUncles) > 8 ) return false;
1849  // This code is not perfect - it would allow up to 8 Uncles after all chicks have
1850  // matured. To stop this merging to >4 is only allowed between June and Dec 31st
1851  return true;
1852 }
bool AllFlocking()
Debug method.
Definition: Partridge_Covey.cpp:2362
const int June
Definition: landscape.h:41

References AllFlocking(), GetUncleNumber(), June, m_map, m_ourChicks, and Landscape::SupplyDayInYear().

Referenced by ManagerCheckMerge().

◆ ChickExtraMortality()

void Partridge_Covey::ChickExtraMortality ( )

Apply extra chick mortality.

2671  {
2672  for ( int i = m_members_size - 1; i >= 0; i-- ) {
2673  if ( m_members[ i ]->GetObjectType() == pob_Chick ) {
2674  if (random(10000) <cfg_par_chick_extra_mort.value()) {
2675  dynamic_cast < Partridge_Chick * > ( m_members[ i ] )->OnYouAreDead();
2676  }
2677  }
2678 }
2679 }
@ pob_Chick
Definition: Partridge_All.h:297
CfgInt cfg_par_chick_extra_mort("PAR_CHICK_EXTRA_MORT", CFG_CUSTOM, 200)
Extra mortality applied to chicks on death of parents.
Partridge chick class.
Definition: Partridge_All.h:581

References cfg_par_chick_extra_mort, GetObjectType(), m_members, m_members_size, pob_Chick, random(), and CfgInt::value().

Referenced by Partridge_Chick::BeginStep().

◆ CoveyEmigrate()

bool Partridge_Covey::CoveyEmigrate ( void  )

Test for covey emigration.

Emigration is a loss to the system, so this just kills everyone in the covey.

2642  {
2643  for ( unsigned i = m_members_size; i >0; i-- ) {
2644  m_members[i-1]->Dying();
2645  }
2646  return true;
2647 }
virtual void Dying()
Definition: PopulationManager.h:266

References TAnimal::Dying(), m_members, and m_members_size.

◆ CoveyIndividualEmigrate()

void Partridge_Covey::CoveyIndividualEmigrate ( void  )

Test for individuals from covey emigrating.

Chance of each individual emigrating if they are not paired (emigration kills them just to remove them from the system - this is safe because if unpaired there will be no knock-on effects).

2655  {
2656  for ( unsigned i = m_members_size; i >0; i-- ) {
2657  if (!m_members[i-1]->ArePaired()) {
2658  if (random(10000)<cfg_IndividualEmigration.value()) {
2659  m_members[i-1]->Dying();
2660  }
2661  }
2662  }
2663 }
CfgInt cfg_IndividualEmigration
bool ArePaired()
Debug method.
Definition: Partridge_Covey.cpp:2384

References ArePaired(), cfg_IndividualEmigration, TAnimal::Dying(), m_members, m_members_size, random(), and CfgInt::value().

◆ CoveyUpdateMemberPositions()

void Partridge_Covey::CoveyUpdateMemberPositions ( int  a_x,
int  a_y 
)
protected

Update all covey members x,y coords.

Sets all covey members to the location a_x, a_y and sets the covey x,y coords to this too.

1093  {
1094  for ( unsigned int i = 0; i < m_members_size; i++ ) {
1095  m_members[ i ]->SetX( a_x );
1096  m_members[ i ]->SetY( a_y );
1097  }
1098  m_Location_x = a_x;
1099  m_Location_y = a_y;
1100 }
int m_Location_y
Definition: PopulationManager.h:228
void SetX(int a_x)
Definition: PopulationManager.h:240
int m_Location_x
Definition: PopulationManager.h:225
void SetY(int a_y)
Definition: PopulationManager.h:243

References TAnimal::m_Location_x, TAnimal::m_Location_y, m_members, m_members_size, TAnimal::SetX(), and TAnimal::SetY().

Referenced by FlyTo(), MoveDistance(), MoveTo(), NestFindFast(), NestFindSlow(), and Partridge_Covey().

◆ DistanceToCovey()

double Partridge_Covey::DistanceToCovey ( Partridge_Covey a_covey)
protected

Get distance too covey.

1319  {
1320  double dx = m_center_x_float - a_covey->XCenterF();
1321  double dy = m_center_y_float - a_covey->YCenterF();
1322  // Divide by two becuase the maximum distance we can be away is half the world
1323  // in our wrap-around world
1324  double wf = ( double )( m_width >> 1 );
1325  double hf = ( double )( m_height >> 1 );
1326  // We need positive numbers
1327  if ( dx < 0 )
1328  dx = -dx;
1329  if ( dy < 0 )
1330  dy = -dy;
1331  // but we don't need numbers bigger than half the world
1332  if ( dx > wf )
1333  dx = m_width - dx;
1334  if ( dy > hf )
1335  dy = m_height - dy;
1336  // The next bit just makes sure that nothing goes out of whack by being too
1337  //small
1338  if ( dx < MIN_MATH_DIST_SQ ) {
1339  dx = MIN_MATH_DIST_SQ + ( double )( random( 100 ) ) / 100.0;
1340  }
1341  if ( dy < MIN_MATH_DIST_SQ ) {
1342  dy = MIN_MATH_DIST_SQ + ( double )( random( 100 ) ) / 100.0;
1343  }
1344  // Returns the squasre of the short sides or 0.0001, whichever is bigger
1345  return max( dx * dx + dy * dy, MIN_MATH_DIST_SQ );
1346 }
double YCenterF(void)
Definition: Partridge_Covey.h:733
double XCenterF(void)
Definition: Partridge_Covey.h:728

References m_center_x_float, m_center_y_float, m_height, m_width, random(), XCenterF(), and YCenterF().

Referenced by DistanceUpdate(), and DistanceUpdate2().

◆ DistanceUpdate()

void Partridge_Covey::DistanceUpdate ( void  )
protected

Updates distance to nearest covey.

Sorts through the list of nearby coveys and finds the distance to the nearest. Stores the square root of this value.

1301  {
1302  m_nearest_covey_dist = ( double )( m_width * m_height );
1303 
1304  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
1305  if ( m_id == g_covey_list[ i ]->ID() ) {
1306  continue;
1307  }
1308  double dist = DistanceToCovey( g_covey_list[ i ] );
1309  if ( dist < m_nearest_covey_dist ) {
1310  m_nearest_covey_dist = dist;
1311  }
1312  }
1314 }
static vector< Partridge_Covey * > g_covey_list
Definition: Partridge_Covey.h:782
double DistanceToCovey(Partridge_Covey *a_covey)
Get distance too covey.
Definition: Partridge_Covey.cpp:1319
unsigned int ID(void)
Definition: Partridge_Covey.h:738

References DistanceToCovey(), g_covey_list, ID(), m_height, m_id, m_nearest_covey_dist, and m_width.

Referenced by HabitatEvaluate(), and MoveDistance().

◆ DistanceUpdate2()

void Partridge_Covey::DistanceUpdate2 ( void  )
protected

Updates distance to fixed nearest covey.

Sorts through the list of nearby coveys and finds the distance to the nearest that is fixed. Stores the square root of this value.

1281  {
1282  m_nearest_covey_dist = ( double )( m_width * m_height );
1283 
1284  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
1285  if ( m_id == g_covey_list[ i ]->ID() ) {
1286  continue;
1287  }
1288  if ( g_covey_list[ i ]->IsFixed() ) {
1289  double dist = DistanceToCovey( g_covey_list[ i ] );
1290  if ( dist < m_nearest_covey_dist ) {
1291  m_nearest_covey_dist = dist;
1292  }
1293  }
1294  }
1296 }
bool IsFixed(void)
Wonder whether the peg is fixed?
Definition: Partridge_Covey.h:577

References DistanceToCovey(), g_covey_list, ID(), IsFixed(), m_height, m_id, m_nearest_covey_dist, and m_width.

Referenced by TooClose().

◆ EndStep()

void Partridge_Covey::EndStep ( void  )
virtual

Covey EndStep.

Reimplemented from TAnimal.

1616  {
1617  if ( m_CurrentStateNo == -1 ) return;
1618  m_step_done = false;
1619  m_move_done = false;
1620  m_assess_done = false;
1621  m_terr_done = false;
1622 }

References m_assess_done, TALMaSSObject::m_CurrentStateNo, m_move_done, m_step_done, and m_terr_done.

◆ FindMateInArea()

Partridge_Female * Partridge_Covey::FindMateInArea ( int  a_max_distance)

Find mate in area.

Loops through the males in the simulation, find first one in state pars_FAttractingMate and within distance a_max_distance, NULL if none.

1561  {
1562  int l_dsq = a_max_distance * a_max_distance;
1563 
1564  TAnimal * l_candidate;
1565 
1567 
1568  l_candidate = m_manager->ObjectLoopFetch();
1569  while ( l_candidate ) {
1570  if ( dynamic_cast < Partridge_Base * > ( l_candidate )->GetState() == pars_FAttractingMate ) {
1571  int l_dx = m_covey_x - l_candidate->Supply_m_Location_x();
1572  int l_dy = m_covey_y - l_candidate->Supply_m_Location_y();
1573  if ( ( l_dx * l_dx + l_dy * l_dy ) < l_dsq ) {
1574  return dynamic_cast < Partridge_Female * > ( l_candidate );
1575  }
1576  }
1577  l_candidate = m_manager->ObjectLoopFetch();
1578  }
1579  return NULL;
1580 }
@ pars_FAttractingMate
Definition: Partridge_All.h:283
Base class for all partridge classes.
Definition: Partridge_All.h:401
TAnimal * ObjectLoopFetch(void)
Definition: Partridge_Population_Manager.cpp:196
void ObjectLoopInit(int ob_type)
Definition: Partridge_Population_Manager.cpp:187
The base class for all ALMaSS animal classes.
Definition: PopulationManager.h:205
int Supply_m_Location_x()
Definition: PopulationManager.h:213
int Supply_m_Location_y()
Definition: PopulationManager.h:216

References m_covey_x, m_covey_y, m_manager, Partridge_Population_Manager::ObjectLoopFetch(), Partridge_Population_Manager::ObjectLoopInit(), pars_FAttractingMate, pob_Female, TAnimal::Supply_m_Location_x(), and TAnimal::Supply_m_Location_y().

Referenced by Partridge_Male::MFindingMate().

◆ FindMeAHusband()

Partridge_Male * Partridge_Covey::FindMeAHusband ( Partridge_Female a_female)

Find mate in covey.

Find mate within the covey (if possible). Return NULL if not.

1534  {
1535  Partridge_Male * l_male;
1536 #ifdef __PAR_DEBUG2
1537  if ( a_male->GetMate() ) {
1538  int rubbish = 0;
1539  }
1540 #endif
1541  for ( unsigned int i = 0; i < m_members_size; i++ ) {
1542  if ( (m_members[ i ]->GetFamily() != a_female->GetFamily()) && (m_members[ i ]->GetObjectType() == pob_Male )) {
1543  l_male = dynamic_cast < Partridge_Male * > ( m_members[ i ] );
1544  if ( !l_male->GetMate() ) return l_male;
1545  }
1546  }
1547  return NULL;
1548 }
int GetFamily(void)
Supply family ID.
Definition: Partridge_All.h:467
Partridge_Object GetObjectType()
Supply object type.
Definition: Partridge_All.h:432

References Partridge_Base::GetFamily(), Partridge_Male::GetMate(), Partridge_Base::GetObjectType(), m_members, m_members_size, and pob_Male.

◆ FindMeAMateInCovey()

Partridge_Female * Partridge_Covey::FindMeAMateInCovey ( int  a_family_counter)

Is their a suitable female mate in the covey?

2334  {
2335  for ( unsigned int i = 0; i < m_members_size; i++ ) {
2336  if ( m_members[ i ]->GetObjectType() == pob_Female ) {
2337  Partridge_Female * pf = dynamic_cast < Partridge_Female * > ( m_members[ i ] );
2338  // Does she have an oldMate
2339  if ( pf->GetMate() == NULL ) {
2340  if ( pf->GetFamily() != a_family_counter )
2341  return pf;
2342  }
2343  }
2344  }
2345  return NULL;
2346 }

References Partridge_Base::GetFamily(), Partridge_Female::GetMate(), GetObjectType(), m_members, m_members_size, and pob_Female.

Referenced by Partridge_Male::MFindingMate().

◆ FindMeAWife()

Partridge_Female * Partridge_Covey::FindMeAWife ( Partridge_Male a_male)

Find mate in covey.

Find mate within the covey (if possible). Return NULL if not.

1518  {
1519  Partridge_Female * l_female;
1520 #ifdef __PAR_DEBUG2
1521  if ( a_female->GetMate() ) {
1522  int rubbish = 0;
1523  }
1524 #endif
1525  for ( unsigned int i = 0; i < m_members_size; i++ ) {
1526  if ( ( m_members[ i ]->GetFamily() != a_male->GetFamily() ) && ( m_members[ i ]->GetObjectType() == pob_Female ) ) {
1527  l_female = dynamic_cast < Partridge_Female * > ( m_members[ i ] );
1528  if ( !l_female->GetMate() ) return l_female;
1529  }
1530  }
1531  return NULL;
1532 }

References Partridge_Base::GetFamily(), Partridge_Female::GetMate(), Partridge_Base::GetObjectType(), m_members, m_members_size, and pob_Female.

◆ FindNeighbour()

Partridge_Covey * Partridge_Covey::FindNeighbour ( )

Finds the closest other covey.

2290  {
2291  // If there are no neighbours then do nothing
2292  if ( m_neighbourlist_size < 1 ) return NULL;
2293  int neighbour = random( m_neighbourlist_size );
2294  /* DEBUG
2295  if ( m_neighbourlist[ neighbour ]->m_CurrentStateNo == -1 ) {
2296  int rubbish = 0;
2297  }
2298  // END DEBUG */
2299  return m_neighbourlist[ neighbour ];
2300 }
Partridge_Covey * m_neighbourlist[50]
List of coveys close to this covey.
Definition: Partridge_Covey.h:284
int m_neighbourlist_size
Number of coveys close to this covey.
Definition: Partridge_Covey.h:286

References m_neighbourlist, m_neighbourlist_size, and random().

Referenced by Partridge_Male::MFindingMate().

◆ FixHabitat()

void Partridge_Covey::FixHabitat ( void  )

Accept this breeding location.

If the quality is found to be good enough, the animal can decide to use it for its own by calling this method.
This updates the peg position to that of the animal, and updates internal state in accordance with it. After FixTerritory() any subsequent calls to Partridge_Covey::SupplyHabitatQuality() will give the quality on the basis of the same size but possibly drifted pushed peg location from the values used in the recent call to Partridge_Covey::AssessTerritoryQuality.

1074  {
1075  int sz = 0;
1076  if ( !m_assess_done ) {
1077  AssessHabitatQuality( sz );
1078  }
1081  m_center_x_float = ( double )m_covey_x;
1082  m_center_y_float = ( double )m_covey_y;
1083  m_terr_done = true;
1086  m_move_done = false;
1087 }
double AssessHabitatQuality(int &a_sz)
Assess habitat quality (with checks)
Definition: Partridge_Covey.cpp:1059
double m_terr_qual
Homerange evaluation score
Definition: Partridge_Covey.h:120

References AssessHabitatQuality(), m_assess_done, m_assess_qual, m_assess_size, m_center_x, m_center_x_float, m_center_y, m_center_y_float, m_covey_x, m_covey_y, m_move_done, m_terr_done, m_terr_qual, and m_terr_size.

Referenced by Partridge_Female::FFindingTerritory().

◆ FlyTo()

bool Partridge_Covey::FlyTo ( int  a_distance)

Fly to

Fly to a random, new location a_distance away. Only allowed if the size of the covey is 1.

1484  {
1485  // New version, 4/8-2003.
1486 
1487  if ( a_distance <= 0 )
1488  return false;
1489 
1490  bool l_did_move = false;
1491 
1492  // The additional '2' is to ensure that rounding
1493  // in the calculations to follow will not cause
1494  // problems.
1495  if ( m_covey_x - a_distance - 2 >= 0 && m_covey_x + a_distance + 2 < m_width && m_covey_y - a_distance - 2 >= 0
1496  && m_covey_y + a_distance + 2 < m_height ) {
1497  l_did_move = FlyToFast( a_distance );
1498  } else {
1499  l_did_move = FlyToSlow( a_distance );
1500  }
1501 
1502  if ( l_did_move ) {
1505  m_terr_done = false;
1506  m_move_done = false;
1507  m_assess_done = false;
1508  m_dist_done = false;
1509  m_center_x_float = ( double )m_center_x;
1510  m_center_y_float = ( double )m_center_y;
1511 
1513  return true;
1514  }
1515  else return false;
1516 }
bool FlyToSlow(int a_distance)
Move a_distance from current covey position (wraparound)
Definition: Partridge_Covey.cpp:1422
bool FlyToFast(int a_distance)
Move a_distance from current covey position.
Definition: Partridge_Covey.cpp:1349

References CoveyUpdateMemberPositions(), FlyToFast(), FlyToSlow(), m_assess_done, m_center_x, m_center_x_float, m_center_y, m_center_y_float, m_covey_x, m_covey_y, m_dist_done, m_height, m_move_done, m_terr_done, and m_width.

Referenced by Partridge_Female::FFindingTerritory(), and Partridge_Male::MFindingMate().

◆ FlyToFast()

bool Partridge_Covey::FlyToFast ( int  a_distance)
protected

Move a_distance from current covey position.

1349  {
1350  // The distance we want to move as a double.
1351  double l_dist = ( double )a_distance;
1352 
1353  // Table Step size, as a double. Calculated so that
1354  // the difference in distance between points
1355  // around the perimeter of our scanning circle
1356  // are approximately 1 meter apart.
1357  // Eeewww... divisions... Avoid as far as possible.
1358  if ( a_distance != m_flyto_dist ) {
1359  m_flyto_dist = a_distance;
1360  m_flyto_steps = ( int )( floor( l_dist * TWO_PI ) );
1361  if ( cfg_par_flyto_stepsize.value() > 1 )
1363 
1364  m_flyto_ts = ( double )cfg_par_flyto_stepsize.value() * ( double )TRIG_TABLE_LENGTH / ( l_dist * TWO_PI );
1365  }
1366 
1367  // Table Step Sum. Set to random start value, corresponding
1368  // to a random angle around the circle.
1369  double l_tss = ( double )random( TRIG_TABLE_LENGTH );
1370 
1371  bool l_found = false;
1372  int l_new_x = -1;
1373  int l_new_y = -1;
1374  int l_poly_cache = -1;
1375  int l_dx_cache = -20000;
1376  int l_dy_cache = -20000;
1377 
1378  for ( int i = 0; i < m_flyto_steps; i++ ) {
1379  if ( l_tss > ( double )( TRIG_TABLE_LENGTH - 1 ) ) {
1380  l_tss = 0.000001;
1381  }
1382  int index = ( int )floor( l_tss );
1383  l_tss += m_flyto_ts;
1384 
1385  int dx = ( int )floor( l_dist * g_trig_cos[ index ] + 0.5 );
1386  int dy = ( int )floor( l_dist * g_trig_sin[ index ] + 0.5 );
1387 
1388  if ( dx == l_dx_cache && dy == l_dy_cache )
1389  continue;
1390  l_dx_cache = dx;
1391  l_dy_cache = dy;
1392  int x = m_covey_x + dx;
1393  int y = m_covey_y - dy;
1394 
1395  int l_poly = m_map->SupplyPolyRef( x, y );
1396  if ( l_poly != l_poly_cache ) {
1397  l_poly_cache = l_poly;
1398  int l_geo = MoveCanMove( m_map->SupplyElementType( l_poly ) );
1399  if ( l_geo == 1 ) {
1400  // Excellent terrain found. Stop immediately.
1401  m_center_x = x;
1402  m_center_y = y;
1403  return true;
1404  } else if ( l_geo == 0 && l_new_x == -1 ) {
1405  // Remember first acceptable location if we cannot do better.
1406  l_new_x = x;
1407  l_new_y = y;
1408  l_found = true;
1409  }
1410  }
1411  }
1412 
1413  // If we get this far, then we only might have found something
1414  // acceptable place to move, though not good.
1415  if ( l_found ) {
1416  m_center_x = l_new_x;
1417  m_center_y = l_new_y;
1418  }
1419  return l_found;
1420 }
static double * g_trig_cos
Definition: Partridge_Covey.cpp:236
static double * g_trig_sin
Definition: Partridge_Covey.cpp:235
#define TRIG_TABLE_LENGTH
Definition: Partridge_Covey.cpp:233
CfgInt cfg_par_flyto_stepsize("PAR_FLYTO_STEPSIZE", CFG_CUSTOM, 1)
int SupplyPolyRef(int a_x, int a_y)
Definition: landscape.h:1488
TTypesOfLandscapeElement SupplyElementType(int a_polyref)
Definition: landscape.h:1110
int MoveCanMove(TTypesOfLandscapeElement a_ele)
Test if we can go there.
Definition: Partridge_Covey.cpp:3221
double m_flyto_ts
costly intermediate variable
Definition: Partridge_Covey.h:98
int m_flyto_steps
costly intermediate variable
Definition: Partridge_Covey.h:94

References cfg_par_flyto_stepsize, g_trig_cos, g_trig_sin, m_center_x, m_center_y, m_covey_x, m_covey_y, m_flyto_dist, m_flyto_steps, m_flyto_ts, m_map, MoveCanMove(), random(), Landscape::SupplyElementType(), Landscape::SupplyPolyRef(), TRIG_TABLE_LENGTH, and CfgInt::value().

Referenced by FlyTo().

◆ FlyToSlow()

bool Partridge_Covey::FlyToSlow ( int  a_distance)
protected

Move a_distance from current covey position (wraparound)

1422  {
1423  double l_dist = ( double )a_distance;
1424 
1425  if ( a_distance != m_flyto_dist ) {
1426  m_flyto_dist = a_distance;
1427  m_flyto_steps = ( int )( floor( l_dist * TWO_PI ) );
1428  if ( cfg_par_flyto_stepsize.value() > 1 )
1430 
1431  m_flyto_ts = ( double )cfg_par_flyto_stepsize.value() * ( double )TRIG_TABLE_LENGTH / ( l_dist * TWO_PI );
1432  }
1433 
1434  double l_tss = ( double )random( TRIG_TABLE_LENGTH );
1435 
1436  bool l_found = false;
1437  int l_new_x = -1;
1438  int l_new_y = -1;
1439  int l_poly_cache = -1;
1440  int l_dx_cache = -20000;
1441  int l_dy_cache = -20000;
1442 
1443  for ( int i = 0; i < m_flyto_steps; i++ ) {
1444  if ( l_tss > ( double )( TRIG_TABLE_LENGTH - 1 ) ) {
1445  l_tss = 0.000001;
1446  }
1447  int index = ( int )floor( l_tss );
1448  l_tss += m_flyto_ts;
1449 
1450  int dx = ( int )floor( l_dist * g_trig_cos[ index ] + 0.5 );
1451  int dy = ( int )floor( l_dist * g_trig_sin[ index ] + 0.5 );
1452 
1453  if ( dx == l_dx_cache && dy == l_dy_cache )
1454  continue;
1455  l_dx_cache = dx;
1456  l_dy_cache = dy;
1457  int x = Norm( m_covey_x + dx, m_width );
1458  int y = Norm( m_covey_y - dy, m_height );
1459 
1460  int l_poly = m_map->SupplyPolyRef( x, y );
1461  if ( l_poly != l_poly_cache ) {
1462  l_poly_cache = l_poly;
1463  int l_geo = MoveCanMove( m_map->SupplyElementType( l_poly ) );
1464  if ( l_geo == 1 ) {
1465  m_center_x = x;
1466  m_center_y = y;
1467  return true;
1468  } else if ( l_geo == 0 && l_new_x == -1 ) {
1469  l_new_x = x;
1470  l_new_y = y;
1471  l_found = true;
1472  }
1473  }
1474  }
1475 
1476  if ( l_found ) {
1477  m_center_x = l_new_x;
1478  m_center_y = l_new_y;
1479  }
1480  return l_found;
1481 }
int Norm(int a_coord, int a_size)
Wrap-around utility function.
Definition: Partridge_Covey.cpp:866

References cfg_par_flyto_stepsize, g_trig_cos, g_trig_sin, m_center_x, m_center_y, m_covey_x, m_covey_y, m_flyto_dist, m_flyto_steps, m_flyto_ts, m_height, m_map, m_width, MoveCanMove(), Norm(), random(), Landscape::SupplyElementType(), Landscape::SupplyPolyRef(), TRIG_TABLE_LENGTH, and CfgInt::value().

Referenced by FlyTo().

◆ ForceLow()

bool Partridge_Covey::ForceLow ( void  )
inline


703  {
704  return m_force_low;
705 }

References m_force_low.

◆ GetAMember()

Partridge_Base * Partridge_Covey::GetAMember ( )

Returns a random member.

1634  {
1635  return m_members[ 0 ];
1636 }

References m_members.

Referenced by ManagerCheckMerge().

◆ GetChickAge()

int Partridge_Covey::GetChickAge ( )
inline

Return chick age.

486  {
487  return m_ChickAge;
488  }

References m_ChickAge.

Referenced by Partridge_Female::FCaringForYoung(), and Partridge_Male::MCaringForYoung().

◆ GetCoveySize()

unsigned int Partridge_Covey::GetCoveySize ( )
inline

◆ GetMaleInCovey()

Partridge_Male * Partridge_Covey::GetMaleInCovey ( )

Find a male in the covey.

2323  {
2324  for ( unsigned int i = 0; i < m_members_size; i++ ) {
2325  if ( m_members[ i ]->GetObjectType() == pob_Male ) {
2326  Partridge_Male * pm = dynamic_cast < Partridge_Male * > ( m_members[ i ] );
2327  return pm;
2328  }
2329  }
2330  return NULL;
2331 }

References GetObjectType(), m_members, m_members_size, and pob_Male.

Referenced by Partridge_Population_Manager::DissolveCovey().

◆ GetmaxAllowedMove()

int Partridge_Covey::GetmaxAllowedMove ( )
inline

Return the max possible move distance today.

411  {
412  return m_maxAllowedMove;
413  }

References m_maxAllowedMove.

Referenced by Partridge_Female::FFlocking().

◆ GetmaxFoodNeedToday()

double Partridge_Covey::GetmaxFoodNeedToday ( )
inline

Return the maximum food need today.

416  {
417  return m_maxFoodNeedToday;
418  }

References m_maxFoodNeedToday.

Referenced by Partridge_Female::FFlocking().

◆ GetMember()

Partridge_Base * Partridge_Covey::GetMember ( int  a_member)

Returns pointer to a_member.

1638  {
1639  return m_members[ a_member ];
1640 }

References m_members.

Referenced by Partridge_Population_Manager::DissolveCovey().

◆ GetObjectType()

◆ GetOurChicks()

int Partridge_Covey::GetOurChicks ( )
inline

Return the number of chicks.

471  {
472  return m_ourChicks;
473  }

References m_ourChicks.

Referenced by BeginStep(), and Partridge_Male::OnMateDying().

◆ GetUncle()

Partridge_Base* Partridge_Covey::GetUncle ( )

Find uncle in covey.

Searches the covey for any bird with the UncleStatus set as true. Or returns NULL if none.

◆ GetUncleNumber()

int Partridge_Covey::GetUncleNumber ( void  )

Returns the number of uncles.

2560  {
2561  int noUncs=0;
2562  for ( unsigned i = 0; i < m_members_size; i++ ) {
2563  if ( m_members[ i ]->GetUncleStatus() ) {
2564  noUncs++;
2565  }
2566  }
2567  return noUncs;
2568 }

References m_members, and m_members_size.

Referenced by ActOnParentDeath(), and CanWeMerge().

◆ GetUnpairedFemale()

Partridge_Female * Partridge_Covey::GetUnpairedFemale ( )

Finds the first unpaired female in the covey.

2304  {
2305  for ( unsigned int i = 0; i < m_members_size; i++ ) {
2306  if ( m_members[ i ]->GetObjectType() == pob_Female ) {
2307  Partridge_Female * pf = dynamic_cast < Partridge_Female * > ( m_members[ i ] );
2308  // Does she have an oldMate
2309  if ( pf->GetOldMate() ) {
2310  if ( IsMember( pf->GetOldMate() ) ) {
2311  return pf;
2312  } else {
2313  pf->RemoveOldMate(false);
2314  }
2315  }
2316  }
2317  }
2318  return NULL;
2319 }
void RemoveOldMate(bool a_knockon)
Forget old mate.
Definition: Partridge_All.h:903
Partridge_Male * GetOldMate(void)
Supply old mate pointer.
Definition: Partridge_All.h:893

References GetObjectType(), Partridge_Female::GetOldMate(), IsMember(), m_members, m_members_size, pob_Female, and Partridge_Female::RemoveOldMate().

Referenced by Partridge_Population_Manager::DissolveCovey().

◆ GetUnpairedFemale_virgin()

Partridge_Female * Partridge_Covey::GetUnpairedFemale_virgin ( )

Finds the first never paired female in the covey.

2350  {
2351  for ( unsigned int i = 0; i < m_members_size; i++ ) {
2352  if ( m_members[ i ]->GetObjectType() == pob_Female ) {
2353  Partridge_Female * pf = dynamic_cast < Partridge_Female * > ( m_members[ i ] );
2354  return pf;
2355  }
2356  }
2357  return NULL;
2358 }

References GetObjectType(), m_members, m_members_size, and pob_Female.

◆ HabitatEvalPoly()

double Partridge_Covey::HabitatEvalPoly ( TTypesOfLandscapeElement  a_cet,
int  a_poly 
)
protected


2769  {
2770  int st;
2771  switch ( a_cet ) {
2772 
2773  // Terrible stuff
2774  case tole_IndividualTree:
2775  case tole_PlantNursery:
2776  case tole_WindTurbine:
2777  case tole_WoodyEnergyCrop:
2778  case tole_WoodlandMargin:
2779  case tole_Pylon:
2780  case tole_DeciduousForest:
2781  case tole_MixedForest:
2782  case tole_ConiferousForest:
2783  case tole_Building:
2784  case tole_UrbanNoVeg:
2785  case tole_AmenityGrass:
2786  return -2.0;
2787 
2788  // Bad stuff.
2789  case tole_MetalledPath:
2790  case tole_Carpark:
2791  case tole_Churchyard:
2792  case tole_Saltmarsh:
2793  case tole_Stream:
2794  case tole_HeritageSite:
2795  case tole_RiversidePlants:
2796  case tole_RiversideTrees:
2797  case tole_Garden:
2798  case tole_Track:
2799  case tole_SmallRoad:
2800  case tole_LargeRoad:
2801  case tole_ActivePit:
2802  case tole_Pond:
2803  case tole_Freshwater:
2804  case tole_River:
2805  case tole_Saltwater:
2806  case tole_Coast:
2807  case tole_BareRock:
2808  case tole_Parkland:
2809  case tole_UrbanPark:
2811  case tole_SandDune:
2812  case tole_Copse:
2813  return -1.0;
2814 
2815  // Questionable.
2816  case tole_NaturalGrassWet:
2817  case tole_StoneWall:
2818  case tole_Fence:
2819  case tole_Hedges:
2820  case tole_Marsh:
2821  case tole_PitDisused:
2822  case tole_OrchardBand:
2823  return 0.0;
2824 
2825  // OK stuff
2826  case tole_RoadsideSlope:
2827  case tole_PermPasture:
2829  return 2.0;
2830  // Good Stuff
2832  case tole_RoadsideVerge:
2833  case tole_Railway:
2834  case tole_FieldBoundary:
2836  case tole_NaturalGrassDry:
2837  case tole_YoungForest: // ?
2838  case tole_Heath:
2839  case tole_Orchard:
2840  case tole_MownGrass:
2841  case tole_Scrub:
2842  case tole_Vildtager:
2843  return cfg_terr_qual_good.value();
2844 
2845  // Really good stuff!
2846  case tole_BeetleBank:
2847  return (double) cfg_nest_hedgebank1.value();
2848  case tole_HedgeBank:
2849  st = m_OurLandscape->SupplyElementSubType( a_cet );
2850  switch ( st ) {
2851  case 0:
2852  return (double) cfg_nest_hedgebank0.value();
2853  case 1:
2854  return (double) cfg_nest_hedgebank1.value();
2855  case 2:
2856  return (double) cfg_nest_hedgebank2.value();
2857  default:
2858  return 100;
2859  }
2860  // Variable, depending on vegetation and condition of same.
2861  case tole_Field:
2863  return (double) HabitatEvalPolyField( a_poly );
2864 
2865  default:
2866  g_msg->Warn( WARN_BUG, "Partridge_Covey::TerrEvalPoly(): Unknown tole type", "" );
2867  exit( 1 );
2868  }
2869 }
CfgFloat cfg_terr_qual_good("PAR_TERR_QUAL_GOOD", CFG_CUSTOM, 4.0)
Nesting quality for OK areas.
CfgInt cfg_nest_hedgebank2("PAR_NEST_HEDGEBANKTWO", CFG_CUSTOM, 200)
Nesting quality for hedgebank type 2.
CfgInt cfg_nest_hedgebank1("PAR_NEST_HEDGEBANKONE", CFG_CUSTOM, 100)
Nesting quality for hedgebank type 1.
CfgInt cfg_nest_hedgebank0("PAR_NEST_HEDGEBANKZERO", CFG_CUSTOM, 1)
Nesting quality for hedgebank type 0.
double value(void)
Definition: configurator.h:118
int SupplyElementSubType(int a_polyref)
Definition: landscape.h:1121
int HabitatEvalPolyField(int a_field)
Evaluate a field's habitat quality.
Definition: Partridge_Covey.cpp:3028
@ tole_BareRock
Definition: tole_declaration.h:75
@ tole_PermPastureTussocky
Definition: tole_declaration.h:45
@ tole_Saltmarsh
Definition: tole_declaration.h:88
@ tole_WoodyEnergyCrop
Definition: tole_declaration.h:94
@ tole_Carpark
Definition: tole_declaration.h:85
@ tole_Coast
Definition: tole_declaration.h:67
@ tole_UrbanNoVeg
Definition: tole_declaration.h:78
@ tole_Stream
Definition: tole_declaration.h:89
@ tole_Saltwater
Definition: tole_declaration.h:66
@ tole_MixedForest
Definition: tole_declaration.h:53
@ tole_HeritageSite
Definition: tole_declaration.h:90
@ tole_WoodlandMargin
Definition: tole_declaration.h:98
@ tole_RoadsideSlope
Definition: tole_declaration.h:83
@ tole_River
Definition: tole_declaration.h:65
@ tole_StoneWall
Definition: tole_declaration.h:56
@ tole_Parkland
Definition: tole_declaration.h:77
@ tole_NaturalGrassWet
Definition: tole_declaration.h:87
@ tole_NaturalGrassDry
Definition: tole_declaration.h:48
@ tole_UrbanPark
Definition: tole_declaration.h:79
@ tole_Pylon
Definition: tole_declaration.h:96
@ tole_PermanentSetaside
Definition: tole_declaration.h:46
@ tole_Garden
Definition: tole_declaration.h:58
@ tole_Pond
Definition: tole_declaration.h:101
@ tole_Scrub
Definition: tole_declaration.h:42
@ tole_Fence
Definition: tole_declaration.h:57
@ tole_Field
Definition: tole_declaration.h:43
@ tole_Copse
Definition: tole_declaration.h:82
@ tole_PermPasture
Definition: tole_declaration.h:47
@ tole_Hedges
Definition: tole_declaration.h:37
@ tole_Track
Definition: tole_declaration.h:59
@ tole_Heath
Definition: tole_declaration.h:70
@ tole_Freshwater
Definition: tole_declaration.h:64
@ tole_PitDisused
Definition: tole_declaration.h:50
@ tole_FieldBoundary
Definition: tole_declaration.h:40
@ tole_PlantNursery
Definition: tole_declaration.h:95
@ tole_DeciduousForest
Definition: tole_declaration.h:52
@ tole_ActivePit
Definition: tole_declaration.h:63
@ tole_RiversidePlants
Definition: tole_declaration.h:49
@ tole_Building
Definition: tole_declaration.h:62
@ tole_RoadsideVerge
Definition: tole_declaration.h:38
@ tole_Vildtager
Definition: tole_declaration.h:99
@ tole_Orchard
Definition: tole_declaration.h:71
@ tole_MownGrass
Definition: tole_declaration.h:74
@ tole_YoungForest
Definition: tole_declaration.h:55
@ tole_OrchardBand
Definition: tole_declaration.h:73
@ tole_SmallRoad
Definition: tole_declaration.h:60
@ tole_Churchyard
Definition: tole_declaration.h:86
@ tole_BuiltUpWithParkland
Definition: tole_declaration.h:80
@ tole_AmenityGrass
Definition: tole_declaration.h:76
@ tole_PermPastureLowYield
Definition: tole_declaration.h:44
@ tole_HedgeBank
Definition: tole_declaration.h:68
@ tole_Railway
Definition: tole_declaration.h:39
@ tole_WindTurbine
Definition: tole_declaration.h:97
@ tole_ConiferousForest
Definition: tole_declaration.h:54
@ tole_SandDune
Definition: tole_declaration.h:81
@ tole_IndividualTree
Definition: tole_declaration.h:93
@ tole_RiversideTrees
Definition: tole_declaration.h:51
@ tole_LargeRoad
Definition: tole_declaration.h:61
@ tole_UnsprayedFieldMargin
Definition: tole_declaration.h:72
@ tole_BeetleBank
Definition: tole_declaration.h:69
@ tole_MetalledPath
Definition: tole_declaration.h:84
@ tole_Marsh
Definition: tole_declaration.h:41

References cfg_nest_hedgebank0, cfg_nest_hedgebank1, cfg_nest_hedgebank2, cfg_terr_qual_good, g_msg, HabitatEvalPolyField(), TAnimal::m_OurLandscape, Landscape::SupplyElementSubType(), tole_ActivePit, tole_AmenityGrass, tole_BareRock, tole_BeetleBank, tole_Building, tole_BuiltUpWithParkland, tole_Carpark, tole_Churchyard, tole_Coast, tole_ConiferousForest, tole_Copse, tole_DeciduousForest, tole_Fence, tole_Field, tole_FieldBoundary, tole_Freshwater, tole_Garden, tole_Heath, tole_HedgeBank, tole_Hedges, tole_HeritageSite, tole_IndividualTree, tole_LargeRoad, tole_Marsh, tole_MetalledPath, tole_MixedForest, tole_MownGrass, tole_NaturalGrassDry, tole_NaturalGrassWet, tole_Orchard, tole_OrchardBand, tole_Parkland, tole_PermanentSetaside, tole_PermPasture, tole_PermPastureLowYield, tole_PermPastureTussocky, tole_PitDisused, tole_PlantNursery, tole_Pond, tole_Pylon, tole_Railway, tole_River, tole_RiversidePlants, tole_RiversideTrees, tole_RoadsideSlope, tole_RoadsideVerge, tole_Saltmarsh, tole_Saltwater, tole_SandDune, tole_Scrub, tole_SmallRoad, tole_StoneWall, tole_Stream, tole_Track, tole_UnsprayedFieldMargin, tole_UrbanNoVeg, tole_UrbanPark, tole_Vildtager, tole_WindTurbine, tole_WoodlandMargin, tole_WoodyEnergyCrop, tole_YoungForest, CfgInt::value(), CfgFloat::value(), MapErrorMsg::Warn(), and WARN_BUG.

Referenced by HabitatEvaluateFast(), and HabitatEvaluateSlow().

◆ HabitatEvalPolyField()

int Partridge_Covey::HabitatEvalPolyField ( int  a_field)
protected

Evaluate a field's habitat quality.

3028  {
3029 
3030  TTypesOfVegetation l_tov = m_map->SupplyVegType( a_field );
3031  int score;
3032  switch ( l_tov ) {
3033  case tov_OFirstYearDanger:
3034  case tov_OGrazingPigs:
3038  score = 0;
3039  break;
3040 
3041  case tov_Carrots:
3042  case tov_FieldPeas:
3043  case tov_FodderBeet:
3044  case tov_SugarBeet:
3045  case tov_OFodderBeet:
3046  case tov_Maize:
3047  case tov_MaizeSilage:
3048  case tov_OMaizeSilage:
3049  case tov_NoGrowth:
3050  case tov_None:
3051  case tov_OPotatoes:
3052  case tov_WinterRape:
3053  case tov_Potatoes:
3054  case tov_PotatoesIndustry:
3055  score = 1;
3056  break;
3057 
3059  case tov_PermanentSetaside:
3060  case tov_FodderGrass:
3063  case tov_Oats:
3064  case tov_OOats:
3065  case tov_OSeedGrass1:
3066  case tov_OSeedGrass2:
3067  case tov_OSpringBarley:
3068  case tov_OSpringBarleyExt:
3071  case tov_OSpringBarleyPigs:
3072  case tov_OTriticale:
3073  case tov_OWinterBarley:
3074  case tov_OWinterBarleyExt:
3075  case tov_OWinterRape:
3076  case tov_OWinterRye:
3078  case tov_OWinterWheat:
3079  case tov_SeedGrass1:
3080  case tov_SeedGrass2:
3081  case tov_SpringBarley:
3082  case tov_SpringBarleySpr:
3086  case tov_SpringBarleyGrass:
3087  case tov_SpringBarleySeed:
3089  case tov_SpringRape:
3090  case tov_SpringWheat:
3091  case tov_Triticale:
3092  case tov_WinterBarley:
3093  case tov_WinterRye:
3094  case tov_WinterWheat:
3095  case tov_WWheatPControl:
3097  case tov_WWheatPTreatment:
3099  case tov_WinterWheatShort:
3103  case tov_OSBarleySilage:
3104  case tov_OCarrots:
3106  case tov_OFieldPeas:
3107  case tov_OFieldPeasSilage:
3108  case tov_YoungForest:
3109  case tov_Heath:
3110  case tov_BroadBeans:
3111 
3112  score = 2;
3113  break;
3114 
3115  /* case tov_OGrassClover1: case tov_OGrassClover2: case tov_OBarleyPeaCloverGrass: case tov_OCarrots:
3116  case tov_OCloverGrassGrazed1: case tov_OCloverGrassGrazed2: case tov_OCloverGrassSilage1: case tov_OFieldPeas:
3117  case tov_OPermanentGrassGrazed: case tov_PermanentGrassGrazed: case tov_PermanentGrassTussocky: return 3.0; */
3118 
3119  case tov_Setaside:
3120  case tov_NaturalGrass:
3121  case tov_OSetaside:
3122  score = 4;
3123  break;
3124 
3125  case tov_Undefined:
3126  default:
3127  return 0;
3128  }
3129  return score;
3130 }
TTypesOfVegetation SupplyVegType(int a_x, int a_y)
Definition: landscape.h:1321
TTypesOfVegetation
Definition: tov_declaration.h:30
@ tov_WWheatPControl
Definition: tov_declaration.h:55
@ tov_OWinterWheatUndersown
Definition: tov_declaration.h:49
@ tov_BroadBeans
Definition: tov_declaration.h:66
@ tov_PermanentGrassGrazed
Definition: tov_declaration.h:49
@ tov_SpringBarleySKManagement
Definition: tov_declaration.h:65
@ tov_OFieldPeas
Definition: tov_declaration.h:43
@ tov_SpringBarleyPTreatment
Definition: tov_declaration.h:63
@ tov_OSpringBarleyPigs
Definition: tov_declaration.h:47
@ tov_WWheatPTreatment
Definition: tov_declaration.h:55
@ tov_PermanentSetaside
Definition: tov_declaration.h:49
@ tov_FodderGrass
Definition: tov_declaration.h:62
@ tov_SeedGrass1
Definition: tov_declaration.h:50
@ tov_OGrazingPigs
Definition: tov_declaration.h:44
@ tov_NoGrowth
Definition: tov_declaration.h:38
@ tov_CloverGrassGrazed2
Definition: tov_declaration.h:33
@ tov_OSpringBarley
Definition: tov_declaration.h:46
@ tov_PotatoesIndustry
Definition: tov_declaration.h:50
@ tov_PermanentGrassTussocky
Definition: tov_declaration.h:49
@ tov_OSpringBarleyExt
Definition: tov_declaration.h:63
@ tov_OFirstYearDanger
Definition: tov_declaration.h:44
@ tov_OWinterRape
Definition: tov_declaration.h:47
@ tov_OPotatoes
Definition: tov_declaration.h:44
@ tov_WinterRape
Definition: tov_declaration.h:53
@ tov_OPermanentGrassGrazed
Definition: tov_declaration.h:44
@ tov_SpringBarley
Definition: tov_declaration.h:52
@ tov_OWinterBarley
Definition: tov_declaration.h:47
@ tov_OSeedGrass1
Definition: tov_declaration.h:46
@ tov_SpringBarleySilage
Definition: tov_declaration.h:52
@ tov_SpringBarleySeed
Definition: tov_declaration.h:52
@ tov_SpringBarleyCloverGrass
Definition: tov_declaration.h:52
@ tov_Carrots
Definition: tov_declaration.h:31
@ tov_FieldPeas
Definition: tov_declaration.h:34
@ tov_WWheatPToxicControl
Definition: tov_declaration.h:55
@ tov_OTriticale
Definition: tov_declaration.h:47
@ tov_OMaizeSilage
Definition: tov_declaration.h:65
@ tov_Triticale
Definition: tov_declaration.h:53
@ tov_OFodderBeet
Definition: tov_declaration.h:65
@ tov_WinterWheat
Definition: tov_declaration.h:55
@ tov_OCarrots
Definition: tov_declaration.h:43
@ tov_OSBarleySilage
Definition: tov_declaration.h:56
@ tov_SpringWheat
Definition: tov_declaration.h:53
@ tov_SeedGrass2
Definition: tov_declaration.h:50
@ tov_Undefined
Definition: tov_declaration.h:114
@ tov_OFieldPeasSilage
Definition: tov_declaration.h:56
@ tov_SugarBeet
Definition: tov_declaration.h:66
@ tov_PermanentGrassLowYield
Definition: tov_declaration.h:63
@ tov_CloverGrassGrazed1
Definition: tov_declaration.h:32
@ tov_SpringRape
Definition: tov_declaration.h:53
@ tov_SpringBarleySpr
Definition: tov_declaration.h:66
@ tov_OSeedGrass2
Definition: tov_declaration.h:46
@ tov_NaturalGrass
Definition: tov_declaration.h:37
@ tov_Oats
Definition: tov_declaration.h:40
@ tov_MaizeSilage
Definition: tov_declaration.h:62
@ tov_OBarleyPeaCloverGrass
Definition: tov_declaration.h:41
@ tov_Maize
Definition: tov_declaration.h:36
@ tov_OSpringBarleyClover
Definition: tov_declaration.h:46
@ tov_OCloverGrassSilage1
Definition: tov_declaration.h:43
@ tov_OCloverGrassGrazed2
Definition: tov_declaration.h:43
@ tov_Potatoes
Definition: tov_declaration.h:50
@ tov_None
Definition: tov_declaration.h:39
@ tov_Setaside
Definition: tov_declaration.h:50
@ tov_OSpringBarleyGrass
Definition: tov_declaration.h:46
@ tov_OWinterWheat
Definition: tov_declaration.h:66
@ tov_OWinterBarleyExt
Definition: tov_declaration.h:65
@ tov_OWinterRye
Definition: tov_declaration.h:49
@ tov_OOats
Definition: tov_declaration.h:44
@ tov_Heath
Definition: tov_declaration.h:66
@ tov_OCloverGrassGrazed1
Definition: tov_declaration.h:43
@ tov_WinterRye
Definition: tov_declaration.h:55
@ tov_FodderBeet
Definition: tov_declaration.h:35
@ tov_SpringBarleyGrass
Definition: tov_declaration.h:52
@ tov_WinterBarley
Definition: tov_declaration.h:53
@ tov_WinterWheatShort
Definition: tov_declaration.h:56
@ tov_YoungForest
Definition: tov_declaration.h:60
@ tov_AgroChemIndustryCereal
Definition: tov_declaration.h:55
@ tov_OSetaside
Definition: tov_declaration.h:46

References m_map, Landscape::SupplyVegType(), tov_AgroChemIndustryCereal, tov_BroadBeans, tov_Carrots, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_FieldPeas, tov_FodderBeet, tov_FodderGrass, tov_Heath, tov_Maize, tov_MaizeSilage, tov_NaturalGrass, tov_NoGrowth, tov_None, tov_Oats, tov_OBarleyPeaCloverGrass, tov_OCarrots, tov_OCloverGrassGrazed1, tov_OCloverGrassGrazed2, tov_OCloverGrassSilage1, tov_OFieldPeas, tov_OFieldPeasSilage, tov_OFirstYearDanger, tov_OFodderBeet, tov_OGrazingPigs, tov_OMaizeSilage, tov_OOats, tov_OPermanentGrassGrazed, tov_OPotatoes, tov_OSBarleySilage, tov_OSeedGrass1, tov_OSeedGrass2, tov_OSetaside, tov_OSpringBarley, tov_OSpringBarleyClover, tov_OSpringBarleyExt, tov_OSpringBarleyGrass, tov_OSpringBarleyPigs, tov_OTriticale, tov_OWinterBarley, tov_OWinterBarleyExt, tov_OWinterRape, tov_OWinterRye, tov_OWinterWheat, tov_OWinterWheatUndersown, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_Potatoes, tov_PotatoesIndustry, tov_SeedGrass1, tov_SeedGrass2, tov_Setaside, tov_SpringBarley, tov_SpringBarleyCloverGrass, tov_SpringBarleyGrass, tov_SpringBarleyPTreatment, tov_SpringBarleySeed, tov_SpringBarleySilage, tov_SpringBarleySKManagement, tov_SpringBarleySpr, tov_SpringRape, tov_SpringWheat, tov_SugarBeet, tov_Triticale, tov_Undefined, tov_WinterBarley, tov_WinterRape, tov_WinterRye, tov_WinterWheat, tov_WinterWheatShort, tov_WWheatPControl, tov_WWheatPToxicControl, tov_WWheatPTreatment, and tov_YoungForest.

Referenced by HabitatEvalPoly().

◆ HabitatEvaluate()

double Partridge_Covey::HabitatEvaluate ( int  a_center_x,
int  a_center_y,
int *  a_size_used,
bool  a_rethink_size 
)
protected

Entry point for habitat evaluation.

Makes sure we have taken other covies into account then figures out which of the habitat evaluation functions to call depending how close to the edge of the world we are.
This way of doing things is used when we need to take other covies into account and cannot rely on the pre-assessed 10mgrid qualities of Partridge_Population_Manager::UpdateNestingCoverMap.

991  {
992  if ( !m_dist_done && a_rethink_size ) {
993  DistanceUpdate();
994  m_dist_done = true;
995  }
996  // l_width_height_half
997  int l_whh;
998  if ( a_rethink_size ) {
999  l_whh = ( ( int )m_nearest_covey_dist ) >> 1;
1000  if ( g_par_terr_max_width.value() < l_whh ) {
1001  l_whh = g_par_terr_max_width.value();
1002  } else if ( l_whh < 50 ) {
1003  l_whh = 50; // 100x100 = minimum possible size
1004  }
1005  * a_size_used = l_whh;
1006  } else {
1007  l_whh = * a_size_used;
1008  }
1009 
1010  int l_min_x_incl = a_center_x - l_whh;
1011  int l_max_x_excl = a_center_x + l_whh;
1012  int l_min_y_incl = a_center_y - l_whh;
1013  int l_max_y_excl = a_center_y + l_whh;
1014 
1015  if ( l_min_x_incl < 0 || l_max_x_excl > m_width || l_min_y_incl < 0 || l_max_y_excl > m_height ) {
1016  return HabitatEvaluateSlow( l_min_x_incl, l_max_x_excl, l_min_y_incl, l_max_y_excl );
1017  }
1018  return HabitatEvaluateFast( l_min_x_incl, l_max_x_excl, l_min_y_incl, l_max_y_excl );
1019 }
double HabitatEvaluateFast(int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
Evaluate habitat (wrap around)
Definition: Partridge_Covey.cpp:926
void DistanceUpdate(void)
Updates distance to nearest covey.
Definition: Partridge_Covey.cpp:1301
double HabitatEvaluateSlow(int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
Definition: Partridge_Covey.cpp:952

References DistanceUpdate(), g_par_terr_max_width, HabitatEvaluateFast(), HabitatEvaluateSlow(), m_dist_done, m_height, m_nearest_covey_dist, m_width, and CfgInt::value().

Referenced by AssessHabitatQuality(), and SupplyHabitatQuality().

◆ HabitatEvaluateFast()

double Partridge_Covey::HabitatEvaluateFast ( int  a_min_x_incl,
int  a_max_x_excl,
int  a_min_y_incl,
int  a_max_y_excl 
)
protected

Evaluate habitat (wrap around)

926  {
927  int l_poly_cache = -1;
928  double l_poly_value = 0.0;
929  double l_qual = 0.0;
930 
931  for ( int y = a_min_y_incl; y < a_max_y_excl; y++ ) {
932  for ( int x = a_min_x_incl; x < a_max_x_excl; x++ ) {
933  // l_current_element_type
935  int l_poly = m_map->SupplyPolyRef( x, y );
936  if ( l_poly != l_poly_cache ) {
937  // New polygon. Reevaluate the
938  // value of the current coordinate.
939  l_cet = m_map->SupplyElementType( x, y );
940  l_poly_value = HabitatEvalPoly( l_cet, l_poly );
941  l_poly_cache = l_poly;
942  }
943  l_qual += l_poly_value;
944  }
945  }
946  return l_qual;
947 }
double HabitatEvalPoly(TTypesOfLandscapeElement a_cet, int a_poly)
Definition: Partridge_Covey.cpp:2769
TTypesOfLandscapeElement
Definition: tole_declaration.h:36

References HabitatEvalPoly(), m_map, Landscape::SupplyElementType(), and Landscape::SupplyPolyRef().

Referenced by HabitatEvaluate().

◆ HabitatEvaluateFaster()

double Partridge_Covey::HabitatEvaluateFaster ( int  a_center_x,
int  a_center_y 
)
protected

Evaluate habitat fast.

The search pattern for finding a territory is to find a place where the territory criteria are OK, then check that we are not too close to other coveys. This way of doing things is called when we want to do the job quickly using the pre-assessed qualmap array updated every week by Partridge_Population_Manager::UpdateNestingCoverMap.

1027  {
1028  //This simply returns the territory value at a_center_x,a_center_y with a
1029  //radius of 50m.\n
1030  a_center_x = a_center_x / 10;
1031  a_center_y = a_center_y / 10;
1032  int l_min_x_incl = a_center_x - 5;
1033  int l_max_x_excl = a_center_x + 5;
1034  int l_min_y_incl = a_center_y - 5;
1035  int l_max_y_excl = a_center_y + 5;
1036 
1037  double qual = 0;
1038  if ((l_min_x_incl<0) || (l_min_y_incl<0) || (l_max_x_excl >= (m_width/10)) || (l_max_y_excl >= (m_height /10)) ) return 0; // ignore near the edge - speed fudge
1039  for ( int i = l_min_x_incl; i < l_min_x_incl + 5; i++ )
1040  {
1041  for ( int j = l_min_y_incl; j < l_min_y_incl + 5; j++ )
1042  {
1044  }
1045  }
1046  return qual;
1047 }
double GetQualIndexed(int a_x, int a_y)
Definition: Partridge_Population_Manager.h:78
CoverTempMap * m_territoryqualmap
Pointer to territory quality map.
Definition: Partridge_Population_Manager.h:165

References CoverTempMap::GetQualIndexed(), m_height, m_manager, Partridge_Population_Manager::m_territoryqualmap, and m_width.

Referenced by AssessHabitatQualityFaster().

◆ HabitatEvaluateSlow()

double Partridge_Covey::HabitatEvaluateSlow ( int  a_min_x_incl,
int  a_max_x_excl,
int  a_min_y_incl,
int  a_max_y_excl 
)
protected


952  {
953  int l_poly_cache = -1;
954  double l_poly_value = 0.0;
955  double l_qual = 0.0;
956 
957  ForIterator * l_fx = new ForIterator( a_min_x_incl, a_max_x_excl, 1, 0, m_width );
958  int * l_lx = l_fx->GetList();
959 
960  ForIterator * l_fy = new ForIterator( a_min_y_incl, a_max_y_excl, 1, 0, m_height );
961  int * l_ly = l_fy->GetList();
962 
963  for ( int iy = 0; iy < l_fy->GetLimit(); iy++ ) {
964  int y = l_ly[ iy ];
965  for ( int ix = 0; ix < l_fx->GetLimit(); ix++ ) {
966  int x = l_lx[ ix ];
967 
968  // l_current_element_type
970  int l_poly = m_map->SupplyPolyRef( x, y );
971  if ( l_poly != l_poly_cache ) {
972  // New polygon. Reevaluate the
973  // value of the current coordinate.
974  l_cet = m_map->SupplyElementType( x, y );
975  l_poly_value = HabitatEvalPoly( l_cet, l_poly );
976  l_poly_cache = l_poly;
977  }
978  l_qual += l_poly_value;
979  }
980  }
981  delete l_fy;
982  delete l_fx;
983  return l_qual;
984 }
Iterator class for wrap around landscape
Definition: Partridge_Covey.h:48
int GetLimit(void)
Get how many points
Definition: Partridge_Covey.h:61
int * GetList(void)
Get pointer to list of points
Definition: Partridge_Covey.h:56

References ForIterator::GetLimit(), ForIterator::GetList(), HabitatEvalPoly(), m_height, m_map, m_width, Landscape::SupplyElementType(), and Landscape::SupplyPolyRef().

Referenced by HabitatEvaluate().

◆ HaveWeChicks()

bool Partridge_Covey::HaveWeChicks ( void  )

Check if covey contains chicks.

Relies on the fact that a covey can only have one set of chicks at a time.

2626  {
2630  for ( unsigned int i = 0; i < m_members_size; i++ ) {
2631  if ( m_members[ i ]->GetObjectType() == pob_Chick ) {
2632  return true;
2633  }
2634  }
2635  return false;
2636 }

References GetObjectType(), m_members, m_members_size, and pob_Chick.

◆ ID()

unsigned int Partridge_Covey::ID ( void  )
inline

◆ IsFixed()

bool Partridge_Covey::IsFixed ( void  )
inline

Wonder whether the peg is fixed?

577  {
578  return m_peg_is_fixed;
579  }

References m_peg_is_fixed.

Referenced by DistanceUpdate2().

◆ IsMember()

bool Partridge_Covey::IsMember ( Partridge_Base a_possible_member)


1709  {
1710  for ( unsigned int i = 0; i < m_members_size; i++ ) {
1711 
1712  // if ( a_possible_member->GetID() == m_members[ i ]->GetID() ) {
1713  if ( a_possible_member == m_members[ i ] ) {
1714  return true;
1715  }
1716  }
1717 
1718  return false;
1719 }

References m_members, and m_members_size.

Referenced by AddMember(), Partridge_Male::AmIaMember(), GetUnpairedFemale(), and RemoveMember().

◆ KillChicks()

void Partridge_Covey::KillChicks ( int  percent)
protected

Kill a proportion of the chicks.

Kills each chick if they fail a probability test.

2595  {
2596  //SanityCheck2(m_ourChicks );
2597  for ( int i = m_members_size - 1; i >= 0; i-- ) {
2598  if ( m_members[ i ]->GetObjectType() == pob_Chick ) {
2599  if ( random( 100 ) < percent )
2600  dynamic_cast < Partridge_Chick * > ( m_members[ i ] )->OnYouAreDead();
2601  }
2602  }
2603  //SanityCheck2(m_ourChicks );
2604 }

References GetObjectType(), m_members, m_members_size, pob_Chick, and random().

Referenced by ActOnParentDeath().

◆ KillExcessChicks()

void Partridge_Covey::KillExcessChicks ( int  remaining)

Kill extra chicks.

Kills chicks so that remaining remain.

2573  {
2574  // Need to figure out if we need to kill any chicks
2575  if ( m_ourChicks < remaining ) return;
2576  Partridge_Chick * pc;
2577  int tokill = m_ourChicks - remaining;
2578  for ( int decimate = 0; decimate < tokill; decimate++ ) {
2579  for ( unsigned i = 0; i < m_members_size; i++ ) {
2580  if ( m_members[ i ]->GetObjectType() == pob_Chick ) {
2581  pc = dynamic_cast < Partridge_Chick * > ( m_members[ i ] );
2582  pc->OnYouAreDead();
2583  break;
2584  }
2585  }
2586  }
2587  //SanityCheck2(m_ourChicks );
2588 }
void OnYouAreDead()
Message handler.
Definition: Partridge_All.cpp:1016

References GetObjectType(), m_members, m_members_size, m_ourChicks, Partridge_Chick::OnYouAreDead(), and pob_Chick.

Referenced by ActOnParentDeath().

◆ LifeEssenceLow()

bool Partridge_Covey::LifeEssenceLow ( void  )
inline


698  {
699  return m_essence_low;
700  }

References m_essence_low.

◆ ManagerCheckMerge() [1/2]

bool Partridge_Covey::ManagerCheckMerge ( int  a_noOfUncles)

Merging test for uncle number.

◆ ManagerCheckMerge() [2/2]

void Partridge_Covey::ManagerCheckMerge ( void  )


1794  {
1795  // This is called by the Tick function once a day between certain dates
1796  // for coveys that are not doing anything special and are only 1 or 2 birds
1797  // Test for merging
1798  if ( random( 100 ) >= cfg_par_merging_chance.value() ) return; // Only one chance per day
1799  unsigned int sz = unsigned(g_covey_list.size());
1800  for ( unsigned int i = 0; i < sz; i++ ) {
1801  Partridge_Covey* p_pc = g_covey_list[ i ];
1802  // Skip ourselves.
1803  if ( m_id == p_pc->ID() ) {
1804  continue;
1805  }
1806  if ( -1 == p_pc->m_CurrentStateNo ) {
1807  continue;
1808  }
1809  // Are we close to someone else?
1810  double dx = abs( m_center_x_float - p_pc->XCenterF() );
1811  double dy = abs( m_center_y_float - p_pc->YCenterF() );
1812  if ( ( dx < cfg_min_merge_dist.value() ) && ( dy < cfg_min_merge_dist.value() ) ) {
1813  // OK we feel like merging - will we be allowed to?
1814  // First find out if the target covey is full
1815  if ( p_pc->CanWeMerge( m_members_size ) ) {
1816  // Takes each member of a_covey and tells it to change covey
1817  Partridge_Base * pb;
1818  //unsigned int nu = g_covey_list[ i ]->GetCoveySize();
1819  unsigned int nu = GetCoveySize(); // are we one or two or three?
1820  for ( unsigned int k = 0; k < nu; k++ ) {
1821  pb = GetAMember();
1822  RemoveMember( pb ); //when the last is removed this covey will vanish
1823  pb->SetUncleStatus( true );
1824  pb->SetCovey( p_pc );
1825  p_pc->AddMember( pb );
1826  }
1827  return; // Done
1828  } // Not allowed to merge if we get here
1829  } // end of in-distance test
1830  } // loop each covey (this must be optimised!)
1831 }
CfgFloat cfg_min_merge_dist("PAR_MIN_MERGE_DIST", CFG_CUSTOM, 50.0)
The minimum merging distance.
CfgInt cfg_par_merging_chance("PAR_MERGE_CHANCE", CFG_CUSTOM, 5)
The merging probability.
void SetCovey(Partridge_Covey *a_covey)
Set covey pointer.
Definition: Partridge_All.h:492
void SetUncleStatus(bool a_Status)
Set uncle status.
Definition: Partridge_All.h:442
The collective for a family of partridges
Definition: Partridge_Covey.h:90
unsigned int GetCoveySize()
Return the covey size.
Definition: Partridge_Covey.h:476
Partridge_Base * GetAMember()
Returns a random member.
Definition: Partridge_Covey.cpp:1634
bool CanWeMerge(int a_NoUncles)
Merging test.
Definition: Partridge_Covey.cpp:1833
void AddMember(Partridge_Base *a_new_member)
Definition: Partridge_Covey.cpp:1644
int RemoveMember(Partridge_Base *a_former_member)
Remove a member from the covey.
Definition: Partridge_Covey.cpp:1664

References AddMember(), CanWeMerge(), cfg_min_merge_dist, cfg_par_merging_chance, g_covey_list, GetAMember(), GetCoveySize(), ID(), m_center_x_float, m_center_y_float, TALMaSSObject::m_CurrentStateNo, m_id, m_members_size, random(), RemoveMember(), Partridge_Base::SetCovey(), Partridge_Base::SetUncleStatus(), CfgInt::value(), CfgFloat::value(), XCenterF(), and YCenterF().

◆ ManagerDriftPos()

void Partridge_Covey::ManagerDriftPos ( void  )


1745  {
1747  return;
1748 
1749  double dx = ( double )m_covey_x - m_center_x_float;
1750  double dy = ( double )m_covey_y - m_center_y_float;
1751 
1752  double l_x_sign = 1.0;
1753  double l_y_sign = 1.0;
1754  double wf = ( double )( m_width >> 1 );
1755  double hf = ( double )( m_height >> 1 );
1756 
1757  if ( dx < 0.0 ) {
1758  dx = -dx;
1759  if ( dx > wf ) {
1760  dx = ( double )m_width - dx;
1761  } else {
1762  l_x_sign = -1.0;
1763  }
1764  } else {
1765  // dx > 0
1766  if ( dx > wf ) {
1767  dx = ( double )m_width - dx;
1768  l_x_sign = -1.0;
1769  }
1770  }
1771 
1772  if ( dy < 0.0 ) {
1773  dy = -dy;
1774  if ( dy > hf ) {
1775  dy = ( double )m_height - dy;
1776  } else {
1777  l_y_sign = -1.0;
1778  }
1779  } else {
1780  if ( dy > hf ) {
1781  dy = ( double )m_height - dy;
1782  l_y_sign = -1.0;
1783  }
1784  }
1785 
1786  double dsum = sqrt( dx * dx + dy * dy );
1787  if ( dsum > 0.0 ) {
1788  m_new_center_x_float += l_x_sign * cfg_par_covey_drift_speed.value() * dx / ( dsum );
1789  m_new_center_y_float += l_y_sign * cfg_par_covey_drift_speed.value() * dy / ( dsum );
1790  }
1791 }
CfgFloat cfg_par_covey_drift_speed("PAR_COVEY_DRIFT_SPEED", CFG_CUSTOM, 2.0)
Drift force on the peg.
CfgBool cfg_par_covey_drift_enable("PAR_COVEY_DRIFT_ENABLE", CFG_CUSTOM, true)
bool value(void)
Definition: configurator.h:135
double m_new_center_y_float
Covey centre as float.
Definition: Partridge_Covey.h:140
double m_new_center_x_float
Covey centre as float.
Definition: Partridge_Covey.h:138

References cfg_par_covey_drift_enable, cfg_par_covey_drift_speed, m_center_x_float, m_center_y_float, m_covey_x, m_covey_y, m_height, m_new_center_x_float, m_new_center_y_float, m_peg_is_fixed, m_permanent_marker, m_width, CfgFloat::value(), and CfgBool::value().

◆ ManagerIsPermanant()

bool Partridge_Covey::ManagerIsPermanant ( void  )
inline

Unused

Is peg permanent
Not used at present

767  {
768  return m_permanent_marker;
769  }

References m_permanent_marker.

Referenced by CoveyManager::DelCovey().

◆ ManagerRethinkPos()

void Partridge_Covey::ManagerRethinkPos ( void  )


1855  {
1856  m_force_low = false;
1859 
1861  return;
1862 
1863  double l_force_x = 0.0;
1864  double l_force_y = 0.0;
1865  double l_pressure_sum = 0.0;
1866  double wf = ( double )( m_width >> 1 );
1867  double hf = ( double )( m_height >> 1 );
1868  double l_x_sign = 1.0;
1869  double l_y_sign = 1.0;
1870 
1871  // Can anyone see this is a doubly nested for() loop?
1872  // Nah, nobody is looking... ;-)
1873  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
1874 
1875  // Skip ourselves.
1876  if ( m_id == g_covey_list[ i ]->ID() ) {
1877  continue;
1878  }
1879 
1880  double dx = m_center_x_float - g_covey_list[ i ]->XCenterF();
1881  double dy = m_center_y_float - g_covey_list[ i ]->YCenterF();
1882 
1883  if ( dx < 0.0 ) {
1884  dx = -dx;
1885  if ( dx > wf ) {
1886  dx = ( double )m_width - dx;
1887  l_x_sign = 1.0;
1888  } else {
1889  l_x_sign = -1.0;
1890  }
1891  } else {
1892  // dx > 0
1893  if ( dx > wf ) {
1894  dx = ( double )m_width - dx;
1895  l_x_sign = -1.0;
1896  } else {
1897  l_x_sign = 1.0;
1898  }
1899  }
1900 
1901  if ( dy < 0.0 ) {
1902  dy = -dy;
1903  if ( dy > hf ) {
1904  dy = ( double )m_height - dy;
1905  l_y_sign = 1.0;
1906  } else {
1907  l_y_sign = -1.0;
1908  }
1909  } else {
1910  if ( dy > hf ) {
1911  dy = ( double )m_height - dy;
1912  l_y_sign = -1.0;
1913  } else {
1914  l_y_sign = 1.0;
1915  }
1916  }
1917 
1918  if ( dx < MIN_MATH_DIST_SQ ) {
1919  dx = MIN_MATH_DIST_SQ;
1920  }
1921  if ( dy < MIN_MATH_DIST_SQ ) {
1922  dy = MIN_MATH_DIST_SQ;
1923  }
1924  double dist = max( dx * dx + dy * dy, MIN_MATH_DIST_SQ );
1925 
1926  if ( dist < cfg_par_force_ignore_dist_sq.value() ) {
1927  l_pressure_sum += Pressure( sqrt( dist ) ); // Eeewww....
1928  l_force_x += l_x_sign * dx / dist; // 'Hurt me plenty.'
1929  l_force_y += l_y_sign * dy / dist;
1930  }
1931  } // End of covey loop
1932 
1933  double l_vector_force = sqrt( l_force_x * l_force_x + l_force_y * l_force_y );
1934 
1935  if ( ( l_vector_force > g_covey_manager->Getpar_force_ignore_below() ) && ( !m_peg_is_fixed ) && ( !m_permanent_marker ) ) {
1938  }
1939 
1940  if ( l_vector_force < cfg_par_force_below.value() )
1941  m_force_low = true;
1942 
1943  m_essence_low = PressureLimitExceeded( l_pressure_sum );
1944 }
CfgFloat cfg_par_force_ignore_dist_sq("PAR_COVEY_FORCE_IGNORE_DIST_SQ", CFG_CUSTOM, 250000.0)
CfgBool cfg_par_force_enable("PAR_COVEY_FORCE_ENABLE", CFG_CUSTOM, true)
Enable the calculation of the repulsive inter-covey 'force'.
CfgFloat cfg_par_force_speed("PAR_COVEY_FORCE_SPEED", CFG_CUSTOM, 2.0)
CfgFloat cfg_par_force_below("PAR_COVEY_FORCE_BELOW", CFG_CUSTOM, 0.1)
double Getpar_force_ignore_below()
Get the minimum interesting force.
Definition: Partridge_Covey.h:822
bool PressureLimitExceeded(double a_pressure)
Test for exceedence of pressure limit.
Definition: Partridge_Covey.cpp:1737
double Pressure(double a_distance)
Get the pressure force.
Definition: Partridge_Covey.cpp:1724

References cfg_par_force_below, cfg_par_force_enable, cfg_par_force_ignore_dist_sq, cfg_par_force_speed, g_covey_list, g_covey_manager, CoveyManager::Getpar_force_ignore_below(), ID(), m_center_x_float, m_center_y_float, m_essence_low, m_force_low, m_height, m_id, m_new_center_x_float, m_new_center_y_float, m_peg_is_fixed, m_permanent_marker, m_width, Pressure(), PressureLimitExceeded(), CfgFloat::value(), and CfgBool::value().

◆ ManagerSetPermanent()

void Partridge_Covey::ManagerSetPermanent ( void  )
inline

Unused

This peg is not associated with a family entity and can never be be moved, nor deleted. It is, well, permanent.
Not used at present

759  {
760  m_permanent_marker = true;
761  }

References m_permanent_marker.

◆ ManagerUpdatePos()

void Partridge_Covey::ManagerUpdatePos ( void  )


1948  {
1950  return;
1951 
1952  if ( m_new_center_x_float < 0.0 )
1953  m_new_center_x_float += ( double )m_width; else if ( m_new_center_x_float > ( double )m_width - 1.0 )
1954  m_new_center_x_float -= ( double )m_width;
1955 
1956  if ( m_new_center_y_float < 0.0 )
1957  m_new_center_y_float += ( double )m_height; else if ( m_new_center_y_float > ( double )m_height - 1.0 )
1958  m_new_center_y_float -= ( double )m_height;
1959 
1962  m_center_x = ( int )m_center_x_float;
1963  m_center_y = ( int )m_center_y_float;
1964  m_terr_done = false;
1965  m_assess_done = false;
1966  m_dist_done = false;
1967 }

References m_assess_done, m_center_x, m_center_x_float, m_center_y, m_center_y_float, m_dist_done, m_height, m_new_center_x_float, m_new_center_y_float, m_peg_is_fixed, m_permanent_marker, m_terr_done, and m_width.

◆ Memberships()

unsigned int Partridge_Covey::Memberships ( void  )
inline

Get covey size.

691  {
692  return m_members_size;
693  }

References m_members_size.

◆ MoveCanMove() [1/2]

int Partridge_Covey::MoveCanMove ( int  a_x,
int  a_y 
)

Test of movement step.

Returns:
     -1: Cannot move here due to element type.
     0: OK to go here.
     1: Exceptionally favorable terrain (for detecting hedges etc.)

857  {
858  return MoveCanMove( m_map->SupplyElementType( a_x, a_y ) );
859 }

References m_map, MoveCanMove(), and Landscape::SupplyElementType().

◆ MoveCanMove() [2/2]

int Partridge_Covey::MoveCanMove ( TTypesOfLandscapeElement  a_ele)
protected

Test if we can go there.

Returns a code for whether the partridges can take chicks onto this polygon type at all (-1), if necessary (0) or by choice (1).

3221  {
3222  switch ( a_ele ) {
3223  case tole_StoneWall:
3224  case tole_Fence:
3225  case tole_Garden:
3226  case tole_Building:
3227  case tole_Pond:
3228  case tole_Freshwater:
3229  case tole_River:
3230  case tole_Saltwater:
3231  case tole_Coast:
3232  case tole_Churchyard:
3233  case tole_Stream:
3234  return -1;
3235 
3236  case tole_IndividualTree:
3237  case tole_PlantNursery:
3238  case tole_WindTurbine:
3239  case tole_WoodyEnergyCrop:
3240  case tole_WoodlandMargin:
3241  case tole_Pylon:
3242  case tole_PermPasture:
3243  case tole_Scrub:
3244  case tole_RiversidePlants:
3245  case tole_RiversideTrees:
3246  case tole_DeciduousForest:
3247  case tole_MixedForest:
3248  case tole_ConiferousForest:
3249  case tole_Marsh:
3250  case tole_PitDisused:
3251  case tole_Track:
3252  case tole_SmallRoad:
3253  case tole_LargeRoad:
3254  case tole_ActivePit:
3255  case tole_Hedges:
3256  case tole_Railway:
3257  case tole_Field:
3262  case tole_YoungForest:
3263  case tole_NaturalGrassDry:
3264  case tole_Heath:
3265  case tole_OrchardBand:
3266  case tole_MownGrass:
3267  case tole_Orchard:
3268  case tole_BareRock:
3269  case tole_AmenityGrass:
3270  case tole_Parkland:
3271  case tole_UrbanNoVeg:
3272  case tole_UrbanPark:
3274  case tole_SandDune:
3275  case tole_Copse:
3276  case tole_NaturalGrassWet:
3277  case tole_RoadsideSlope:
3278  case tole_MetalledPath:
3279  case tole_Carpark:
3280  case tole_Saltmarsh:
3281  case tole_HeritageSite:
3282  return 0;
3283 
3284  case tole_RoadsideVerge:
3285  case tole_FieldBoundary:
3286  case tole_HedgeBank:
3287  case tole_BeetleBank:
3288  case tole_Vildtager:
3289  return 1;
3290 
3291  default:
3292  g_msg->Warn( WARN_BUG, "Partridge_Covey::MoveCanMove(): Unknown tole type", "" );
3293  exit( 1 );
3294  break;
3295  }
3296 }

References g_msg, tole_ActivePit, tole_AmenityGrass, tole_BareRock, tole_BeetleBank, tole_Building, tole_BuiltUpWithParkland, tole_Carpark, tole_Churchyard, tole_Coast, tole_ConiferousForest, tole_Copse, tole_DeciduousForest, tole_Fence, tole_Field, tole_FieldBoundary, tole_Freshwater, tole_Garden, tole_Heath, tole_HedgeBank, tole_Hedges, tole_HeritageSite, tole_IndividualTree, tole_LargeRoad, tole_Marsh, tole_MetalledPath, tole_MixedForest, tole_MownGrass, tole_NaturalGrassDry, tole_NaturalGrassWet, tole_Orchard, tole_OrchardBand, tole_Parkland, tole_PermanentSetaside, tole_PermPasture, tole_PermPastureLowYield, tole_PermPastureTussocky, tole_PitDisused, tole_PlantNursery, tole_Pond, tole_Pylon, tole_Railway, tole_River, tole_RiversidePlants, tole_RiversideTrees, tole_RoadsideSlope, tole_RoadsideVerge, tole_Saltmarsh, tole_Saltwater, tole_SandDune, tole_Scrub, tole_SmallRoad, tole_StoneWall, tole_Stream, tole_Track, tole_UnsprayedFieldMargin, tole_UrbanNoVeg, tole_UrbanPark, tole_Vildtager, tole_WindTurbine, tole_WoodlandMargin, tole_WoodyEnergyCrop, tole_YoungForest, MapErrorMsg::Warn(), and WARN_BUG.

Referenced by FlyToFast(), FlyToSlow(), MoveCanMove(), MoveOptimalDirectionFast(), and MoveOptimalDirectionSlow().

◆ MoveDirectionsAllowed()

void Partridge_Covey::MoveDirectionsAllowed ( int  a_x,
int  a_y 
)
protected

Test possible movement directions.

397  {
398  // Finding the possible directions allowed by the location of the
399  // peg is slightly complicated, because the actual covey position
400  // may be on the other side of a map boundary.
401 
402  int l_dx = m_center_x - a_x;
403  int l_dy = m_center_y - a_y;
404 
405  if ( l_dx < 0 ) {
406  if ( -l_dx > ( m_width >> 1 ) ) {
407  l_dx += m_width;
408  }
409  } else {
410  if ( l_dx > ( m_width >> 1 ) ) {
411  l_dx -= m_width;
412  }
413  }
414 
415  if ( l_dy < 0 ) {
416  if ( -l_dy > ( m_height >> 1 ) ) {
417  l_dy += m_height;
418  }
419  } else {
420  if ( l_dy > ( m_height >> 1 ) ) {
421  l_dy -= m_height;
422  }
423  }
424 
425 #ifdef PAR_DEBUG
426  printf( "dX, dY : %d %d\n", l_dx, l_dy );
427 #endif
428 
429  // We now have l_dx and l_dy normalized wrt. to the map borders.
430  // Finding the true distance and direction to the peg is now trivial.
431  int l_dist_sq = l_dx * l_dx + l_dy * l_dy;
432 
433  if ( l_dx >= 0 ) {
434  // The peg is in 1st or 2nd quadrant as seen from the covey.
435  if ( l_dy < 0 ) {
436  // 1st quadrant. Check octant!
437  if ( -l_dy > l_dx ) {
438  // 1st octant.
439  m_move_allowed[ direction_n ] = true;
440  m_move_allowed[ direction_ne ] = true;
441  m_move_allowed[ direction_e ] = MoveTryExclude( l_dist_sq );
442  m_move_allowed[ direction_nw ] = MoveTryExclude( l_dist_sq );
447  } else {
448  // 2nd octant.
449  m_move_allowed[ direction_ne ] = true;
450  m_move_allowed[ direction_e ] = true;
451  m_move_allowed[ direction_n ] = MoveTryExclude( l_dist_sq );
452  m_move_allowed[ direction_se ] = MoveTryExclude( l_dist_sq );
457  }
458  } else {
459  // 2nd quadrant clockwise from north.
460  if ( l_dx > l_dy ) {
461  // 3rd octant.
462  m_move_allowed[ direction_e ] = true;
463  m_move_allowed[ direction_se ] = true;
464  m_move_allowed[ direction_ne ] = MoveTryExclude( l_dist_sq );
465  m_move_allowed[ direction_s ] = MoveTryExclude( l_dist_sq );
470  } else {
471  // 4th octant.
472  m_move_allowed[ direction_se ] = true;
473  m_move_allowed[ direction_s ] = true;
474  m_move_allowed[ direction_e ] = MoveTryExclude( l_dist_sq );
475  m_move_allowed[ direction_sw ] = MoveTryExclude( l_dist_sq );
480  }
481  }
482  } else {
483  // l_dx < 0
484  // The peg is in the 3rd or the 4th quadrant, clockwise from north.
485  if ( l_dy >= 0 ) {
486  // 3rd quadrant.
487  if ( l_dy > -l_dx ) {
488  // 5th octant.
489  m_move_allowed[ direction_s ] = true;
490  m_move_allowed[ direction_sw ] = true;
491  m_move_allowed[ direction_se ] = MoveTryExclude( l_dist_sq );
492  m_move_allowed[ direction_w ] = MoveTryExclude( l_dist_sq );
497  } else {
498  // 6th octant.
499  m_move_allowed[ direction_sw ] = true;
500  m_move_allowed[ direction_w ] = true;
501  m_move_allowed[ direction_s ] = MoveTryExclude( l_dist_sq );
502  m_move_allowed[ direction_nw ] = MoveTryExclude( l_dist_sq );
507  }
508  } else {
509  // l_dy < 0
510  // 4th quadrant.
511  if ( l_dx < l_dy ) {
512  // 7th octant.
513  m_move_allowed[ direction_w ] = true;
514  m_move_allowed[ direction_nw ] = true;
515  m_move_allowed[ direction_n ] = MoveTryExclude( l_dist_sq );
516  m_move_allowed[ direction_sw ] = MoveTryExclude( l_dist_sq );
521  } else {
522  // 8th octant.
523  m_move_allowed[ direction_nw ] = true;
524  m_move_allowed[ direction_n ] = true;
525  m_move_allowed[ direction_ne ] = MoveTryExclude( l_dist_sq );
526  m_move_allowed[ direction_w ] = MoveTryExclude( l_dist_sq );
531  }
532  }
533  }
534 }
bool m_move_allowed[8]
Definition: Partridge_Covey.cpp:228
bool MoveTryExcludeHarder(int a_dist_sq)
Uses the peg force to exclude possible movement directions.
Definition: Partridge_Covey.cpp:2750
bool MoveTryExclude(int a_dist_sq)
Uses the peg force to exclude possible movement directions.
Definition: Partridge_Covey.cpp:2735
@ direction_se
Definition: landscape.h:60
@ direction_nw
Definition: landscape.h:60
@ direction_w
Definition: landscape.h:60
@ direction_s
Definition: landscape.h:60
@ direction_ne
Definition: landscape.h:60
@ direction_n
Definition: landscape.h:60
@ direction_e
Definition: landscape.h:60
@ direction_sw
Definition: landscape.h:60

References direction_e, direction_n, direction_ne, direction_nw, direction_s, direction_se, direction_sw, direction_w, m_center_x, m_center_y, m_height, m_move_allowed, m_width, MoveTryExclude(), and MoveTryExcludeHarder().

Referenced by MoveDistance(), and MoveTo().

◆ MoveDistance()

void Partridge_Covey::MoveDistance ( int  a_max_distance,
int  a_step_size,
double  a_food_density_needed 
)

Entry point for movement.

Move distance needs to take into accound the moves possible, the food available, the peg location, and the history of moves.

This is where the partridge model spends much of its time (when there are chicks to feed). It is possible that these routines could be optimised, but they are also the most likely to be modified in the future, so too much optimisation may be a waste of time.

652  {
660  if ( m_move_done )
661  return;
662 
663  if ( !m_dist_done ) {
664  m_dist_done = true;
665  DistanceUpdate();
666  }
667 
668  if ( m_nest_on_nest ) {
669  g_msg->Warn( WARN_BUG, "Partridge_Covey::MoveDistance(): ", "Asked to move while on nest." );
670  exit( 1 );
671  }
672 
673  m_dist_moved = 0.0;
674  m_food_today = 0.0;
675  int l_x = m_covey_x;
676  int l_y = m_covey_y;
677 
678  if ( a_step_size != m_move_step_size ) {
679  m_move_step_size = a_step_size;
680  m_move_step_size_inv = 1.0 / ( double )a_step_size;
681  }
682 
683 /*
684  if ( m_move_get_enable ) {
685  m_move_get_index = 0;
686  m_move_get_size = 0;
687  }
688 */
689  while ( m_dist_moved < ( double )a_max_distance && m_food_today < a_food_density_needed ) {
690 
691  // Build list of possible directions, given the location
692  // of the peg.
693  MoveDirectionsAllowed( l_x, l_y );
694 
695 #ifdef PAR_DEBUG
696  printf( "Allowed : %d %d %d %d %d %d %d %d\n", m_move_allowed[ 0 ], m_move_allowed[ 1 ], m_move_allowed[ 2 ],
698 #endif
699 
700  // Build list of movement evaluations in
701  // m_move_list[] from our present location.
702  if ( l_x - a_step_size >= 0 && l_x + a_step_size < m_width && l_y - a_step_size >= 0 && l_y + a_step_size < m_height ) {
703  MoveOptimalDirectionFast( l_x, l_y );
704  } else {
705  MoveOptimalDirectionSlow( l_x, l_y );
706  }
707 
708 #ifdef PAR_DEBUG
709  printf( "DirQual : %d %d %d %d %d %d %d %d\n", m_move_list[ 0 ], m_move_list[ 1 ], m_move_list[ 2 ], m_move_list[ 3 ],
710  m_move_list[ 4 ], m_move_list[ 5 ], m_move_list[ 6 ], m_move_list[ 7 ] );
711 #endif
712 
713  // Take peg location and possibly past history/memory into
714  // account.
715  int l_dir = MoveWeighDirection( l_x, l_y );
716  MoveQualMemory( m_move_list[ l_dir ] );
717 
718 #ifdef PAR_DEBUG
719  printf( "QualMemo: 1: %d 2: %d 3: %d\n", m_move_qual_memory[ 1 ], m_move_qual_memory[ 2 ], m_move_qual_memory[ 3 ] );
720  printf( "Selected: %d\n", l_dir );
721 #endif
722  m_move_whence_we_came = Norm( l_dir - 4, 8 );
723 
724  // We now have the direction that we want to move in l_dir.
725  m_food_today += m_move_dir_qual[ l_dir ];
726 
727  // This call also updates l_x and l_y. Nasty, nasty. ;-)
728  m_dist_moved += MoveDoIt( & l_x, & l_y, l_dir, a_step_size );
729 #ifdef PAR_DEBUG
730  //printf("Dist Sum: %f\n", m_dist_moved );
731  printf( "Coords : %d %d\n\n", l_x, l_y );
732 #endif
733 
734  // Collect movement reports.
735 /*
736 if ( m_move_get_enable ) {
737  m_move_get_size++;
738  m_move_get_x.resize( m_move_get_size );
739  m_move_get_y.resize( m_move_get_size );
740  m_move_get_x[ m_move_get_index ] = l_x;
741  m_move_get_y[ m_move_get_index ] = l_y;
742  m_move_get_index++;
743  }
744 */
745  }
746 
747  CoveyUpdateMemberPositions( l_x, l_y );
748  m_move_get_index = 0;
749  m_covey_x = l_x;
750  m_covey_y = l_y;
751  m_assess_done = false;
752  m_move_done = true;
753 }
int m_move_list[8]
Definition: Partridge_Covey.cpp:226
double m_move_dir_qual[8]
Definition: Partridge_Covey.cpp:227
int m_move_get_index
Internal variable.
Definition: Partridge_Covey.h:304
void MoveOptimalDirectionFast(int a_x, int a_y)
Choose best foraging direction (wrap around)
Definition: Partridge_Covey.cpp:3667
int MoveWeighDirection(int a_x, int a_y)
Weighted foraging walk.
Definition: Partridge_Covey.cpp:344
double MoveDoIt(int *a_x, int *a_y, int a_dir, int a_step_size)
We know where we want to go. Now do it!
Definition: Partridge_Covey.cpp:811
void MoveQualMemory(int a_qual)
Make a move based on memory of quality.
Definition: Partridge_Covey.cpp:538
void MoveOptimalDirectionSlow(int a_x, int a_y)
Choose best foraging direction.
Definition: Partridge_Covey.cpp:3404
void MoveDirectionsAllowed(int a_x, int a_y)
Test possible movement directions.
Definition: Partridge_Covey.cpp:397

References CoveyUpdateMemberPositions(), DistanceUpdate(), g_msg, m_assess_done, m_covey_x, m_covey_y, m_dist_done, m_dist_moved, m_food_today, m_height, m_move_allowed, m_move_dir_qual, m_move_done, m_move_get_index, m_move_list, m_move_qual_memory, m_move_step_size, m_move_step_size_inv, m_move_whence_we_came, m_nest_on_nest, MoveDirectionsAllowed(), MoveDoIt(), MoveOptimalDirectionFast(), MoveOptimalDirectionSlow(), MoveQualMemory(), MoveWeighDirection(), Norm(), MapErrorMsg::Warn(), and WARN_BUG.

Referenced by Partridge_Chick::BeginStep(), Partridge_Chick2::BeginStep(), Partridge_Female::FCaringForYoung(), Partridge_Female::FFlocking(), Partridge_Male::MCaringForYoung(), and Partridge_Male::MFlocking().

◆ MoveDoIt()

double Partridge_Covey::MoveDoIt ( int *  a_x,
int *  a_y,
int  a_dir,
int  a_step_size 
)
protected

We know where we want to go. Now do it!

811  {
812  int l_diag_length = ( int )( ( double )a_step_size * 0.71 );
813  double l_length = ( double )a_step_size;
814 
815  switch ( a_dir ) {
816  case direction_n:
817  * a_y -= a_step_size;
818  break;
819 
820  case direction_ne:
821  * a_y -= l_diag_length;
822  * a_x += l_diag_length;
823  break;
824  case direction_e:
825  * a_x += a_step_size;
826  break;
827  case direction_se:
828  * a_y += l_diag_length;
829  * a_x += l_diag_length;
830  break;
831  case direction_s:
832  * a_y += a_step_size;
833  break;
834  case direction_sw:
835  * a_y += l_diag_length;
836  * a_x -= l_diag_length;
837  break;
838  case direction_w:
839  * a_x -= a_step_size;
840  break;
841  case direction_nw:
842  * a_y -= l_diag_length;
843  * a_x -= l_diag_length;
844  break;
845  }
846 
847  * a_x = Norm( * a_x, m_width );
848  * a_y = Norm( * a_y, m_height );
849  return l_length;
850 }

References direction_e, direction_n, direction_ne, direction_nw, direction_s, direction_se, direction_sw, direction_w, m_height, m_width, and Norm().

Referenced by MoveDistance(), and MoveTo().

◆ MoveEvalEdgesAndQual()

int Partridge_Covey::MoveEvalEdgesAndQual ( int  a_edges,
double  a_qual 
)
protected

Move evaluation taking edges into account.

This method must do an evaluation of this particular step given:

  • a_edges: Number of 'edge' squares encountered if moving down this path. See Partridge_Covey::MoveCanMove() below.
  • m_move_step_size: You guessed it. An int.
  • m_move_step_size_inv: The inverse of m_move_step_size as a double. Both of these are updated automatically.
  • a_qual: The sum of the values returned by MoveMagicVegToFood() above times the length of the segments with those values.


a_edges must be taken into account to ensure a preference of moving along field edges, hedges etc.
Values returned should be within the range of [1:3], 3 being most preferable.

2684  {
2702 #ifdef MOVE_EVAL_KLUDGE
2703  if ( a_edges > 2 )
2704  return 3;
2705  if ( a_edges > 0 )
2706  return 2;
2707  return 1;
2708 
2709 #else
2710  int result = 2;
2711  double score = m_move_step_size_inv * a_qual;
2712  // if (score<cfg_par_lowqualthreshold.value())
2713  // result=1; //
2714  if ( score > cfg_par_highqualthreshold.value() )
2715  result = 3;
2716  // Result is 1 or 3 before edge evaluation
2717  // We have one special case, where food is 3 and edges are 2
2718  // correcting for this gives an even distributed result of 1,2,3
2719  if ( a_edges > 2 ) result += 3; else if ( a_edges > 0 ) {
2720  // The special case, where food is 3 and edges are 2
2721  if ( result == 3 ) result += 3; else result += 2;
2722  } else
2723  result += 1;
2724  // Result is now 2, 4 or 6
2725  result = result >> 1;
2726  return result;
2727 #endif
2728 }
CfgInt cfg_par_highqualthreshold("PAR_HIGHQUALTHRESHOLD", CFG_CUSTOM, 18)
An arbitrary value for determine movement quality.

References cfg_par_highqualthreshold, m_move_step_size_inv, and CfgInt::value().

Referenced by MoveOptimalDirectionFast(), and MoveOptimalDirectionSlow().

◆ MoveMagicVegToFood()

double Partridge_Covey::MoveMagicVegToFood ( int  a_polygon)
protected

Move optimising food intake.

This is the primary method responsible for generating food intake and local movement when chicks are present. The idea is to take each step optimally dependent on food availability, with occaisional mis-steps, and if no one direction is optimal then pick randomly. If there is no choice we can back-track.

This section determine the effect of modern landscapes on food availability. Here the problem is that we asume fields are low in food due to a lower insect biomass. The effects of structure should be the same as in the 1950s. However, the question is whether we should treat all habitats as impoverished or just the fields, all fields or just arable fields. The default position is all fields and then allow a scaling factor for patchiness, and assume non-field habitats are not affected - this is not perfect an may need to be revisited in future versions

3147  {
3148  double l_magic = m_map->SupplyInsects( a_polygon ) * cfg_parinsectScaler.value();
3149 #ifdef __P1950s
3150  // ***CJT***
3151  // Problem was that 1950s were calibrated with cfg_1950sinsects set to 1.0
3152  // we have therefore to scale the insects values we get for non-1950s to be lower somehow - preferably without making it run slow
3153  // Line removed
3154 #else
3161  //if ( (!m_map->SupplyVegPatchy(a_polygon)) || (Type == tole_Field || Type == tole_PermPastureTussocky || Type == tole_PermPasture || Type == tole_PermanentSetaside || Type == tole_PermPastureLowYield)) {
3162  if ((!m_map->SupplyVegPatchy(a_polygon)) ) {
3163  if ((Type == tole_Field || Type == tole_PermPastureTussocky || Type == tole_PermPasture || Type == tole_PermanentSetaside || Type == tole_PermPastureLowYield)) { l_magic*=(cfg_NOT1950sinsects.value());
3164  if (m_map->SupplyHasTramlines( a_polygon )) l_magic*=1.5; // extra for tramlines
3165  }
3166  } // otherwise we assume it is like the 1950s
3167 #endif
3168  /* **CJT** 20/7/2010
3169  double height = m_map->SupplyVegHeight( a_polygon );
3170  int l_height_bin = ( int )( height * cfg_par_hei_hindrance_inv.value() );
3171  if ( l_height_bin > 3 ) l_height_bin = 3;
3172  */
3173  // *** CJT *** 1 July 2010 Code below relies on biomass - but this is skylark based code and should be altered to
3174  // density. At the same time some alteration of the height response was required - hence change to HB_Impedence.txt
3175  /*
3176  double bio = m_map->SupplyVegBiomass( a_polygon );
3177  int l_biomass_bin = ( int )( bio * cfg_par_bio_hindrance_inv.value() );;
3178  if ( l_biomass_bin > 3 ) l_biomass_bin = 3;
3179  return l_magic * g_move_veg_structure[ l_height_bin ] [ l_biomass_bin ];
3180 
3181  /*/
3182  /*
3183  double dens = m_map->SupplyVegDensity( a_polygon );
3184  int l_density_bin = ( int )( dens * cfg_par_bio_hindrance_inv.value() );;
3185  if ( l_density_bin > 3 ) l_density_bin = 3;
3186  return l_magic * g_move_veg_structure[ l_height_bin ] [ l_density_bin ];
3187  */
3188  // This section calculates the hindrance based on linear interpolation after the first height category
3189  // The slope (0.25) is scaled by cfg_par_hei_hindrance_inv and cfg_par_bio_hindrance_inv
3190  double height = m_map->SupplyVegHeight( a_polygon );
3191  double l_height_bin = ( height * cfg_par_hei_hindrance_inv.value() ) - 1.0;
3192  if (l_height_bin < 0.0 ) return l_magic; // So short there is no hindrance
3193  double dens = m_map->SupplyVegDensity( a_polygon );
3194  double l_density_bin = ( dens * cfg_par_bio_hindrance_inv.value() );
3195  // We need to restrict the upper end to avoid one factor outweighing the other e.g. if density is very high but height is only just >0.0
3196  if (l_density_bin > 4.0 ) l_density_bin = 4.0;
3197  if (l_height_bin > 4.0 ) l_height_bin = 4.0;
3198  double l_intermediate = 1.0 -(( l_density_bin + l_height_bin - 2.0 ) * 0.25);
3199  if (l_intermediate <0.0) return 0.0;
3200  if (l_intermediate >= 1.0) return l_magic;
3201  return l_magic * l_intermediate;
3202 
3203 }
CfgFloat cfg_par_bio_hindrance_inv("PAR_BIO_HINDRANCE", CFG_CUSTOM, 0.00667)
CfgFloat cfg_NOT1950sinsects("PAR_NOTFIFTIESINSECTSSCALER", CFG_CUSTOM, 0.1)
Default for 2000s, 1950s=1.0.
CfgFloat cfg_par_hei_hindrance_inv("PAR_HEI_HINDRANCE", CFG_CUSTOM, 0.04)
CfgFloat cfg_parinsectScaler("PAR_INSECTSCALER", CFG_CUSTOM, 0.5)
Default for 2000s, 1950s=1.0.
int SupplyVegDensity(int a_polyref)
Definition: landscape.h:975
double SupplyInsects(int a_polyref)
Definition: landscape.h:1088
double SupplyVegHeight(int a_polyref)
Definition: landscape.h:936
bool SupplyHasTramlines(int a_x, int a_y)
Definition: landscape.h:1252
bool SupplyVegPatchy(int a_polyref)
Definition: landscape.h:986

References cfg_NOT1950sinsects, cfg_par_bio_hindrance_inv, cfg_par_hei_hindrance_inv, cfg_parinsectScaler, m_map, Landscape::SupplyElementType(), Landscape::SupplyHasTramlines(), Landscape::SupplyInsects(), Landscape::SupplyVegDensity(), Landscape::SupplyVegHeight(), Landscape::SupplyVegPatchy(), tole_Field, tole_PermanentSetaside, tole_PermPasture, tole_PermPastureLowYield, tole_PermPastureTussocky, and CfgFloat::value().

Referenced by MoveOptimalDirectionFast(), and MoveOptimalDirectionSlow().

◆ MoveOptimalDirectionFast()

void Partridge_Covey::MoveOptimalDirectionFast ( int  a_x,
int  a_y 
)
protected

Choose best foraging direction (wrap around)

See MoveOptimalDirectionSlow for details

Rule: Preferred direction is the one, which gives the best food return.

Sum of distance times 'magic' vegetation2foodvaluepersitance() method.
Each tov type has a constant, which we can use to multiply the insect biomass with (default is now that all are 1.0). We then have to modify this value with some function() of vegetation structure. function() is a precalculated value from 0.0 to 1.0, given as a 4x4 array from vegetation height and biomass.
Also need to ensure the covey moves along the hedges etc.

3667  {
3668  int l_diag_length = ( int )( ( double )m_move_step_size * 0.71 );
3669 
3670  int l_geo_cache = 0;
3671  double l_quality = 0.0;
3672  double l_qual_cache = 0.0;
3673  int l_fantastic = 0;
3674  int l_poly_cache = -1;
3675 
3676  // North.
3678 
3679  if ( m_move_allowed[ direction_n ] ) {
3680  for ( int y = a_y - 1; y >= a_y - m_move_step_size; y-- ) {
3681  int l_poly = m_map->SupplyPolyRef( a_x, y );
3682  if ( l_poly != l_poly_cache ) {
3683  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3684  if ( l_geo_cache == -1 ) {
3685  m_move_list[ direction_n ] = 0;
3686  break;
3687  }
3688  l_poly_cache = l_poly;
3689  l_qual_cache = MoveMagicVegToFood( l_poly );
3690  }
3691  l_fantastic += l_geo_cache;
3692  l_quality += l_qual_cache;
3693  }
3694  }
3695  m_move_dir_qual[ direction_n ] = l_quality;
3696  if ( m_move_list[ direction_n ] ) {
3697  m_move_list[ direction_n ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3698  }
3699 
3700  // Northeast.
3701  l_quality = 0.0;
3702  l_fantastic = 0;
3704  l_qual_cache = 0.0;
3705  l_poly_cache = -1;
3706 
3707  if ( m_move_allowed[ direction_ne ] ) {
3708  for ( int y = a_y - 1, x = a_x + 1; y >= a_y - l_diag_length; y--, x++ ) {
3709  int l_poly = m_map->SupplyPolyRef( x, y );
3710  if ( l_poly != l_poly_cache ) {
3711  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3712  if ( l_geo_cache == -1 ) {
3713  m_move_list[ direction_ne ] = 0;
3714  break;
3715  }
3716  l_poly_cache = l_poly;
3717  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3718  }
3719  l_fantastic += l_geo_cache;
3720  l_quality += l_qual_cache;
3721  }
3722  }
3723  m_move_dir_qual[ direction_ne ] = l_quality;
3724  if ( m_move_list[ direction_ne ] ) {
3725  m_move_list[ direction_ne ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3726  }
3727 
3728  // East.
3729  l_quality = 0.0;
3730  l_fantastic = 0;
3732  l_qual_cache = 0.0;
3733  l_poly_cache = -1;
3734 
3735  if ( m_move_allowed[ direction_e ] ) {
3736  for ( int x = a_x + 1; x <= a_x + m_move_step_size; x++ ) {
3737  int l_poly = m_map->SupplyPolyRef( x, a_y );
3738  if ( l_poly != l_poly_cache ) {
3739  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3740  if ( l_geo_cache == -1 ) {
3741  m_move_list[ direction_e ] = 0;
3742  break;
3743  }
3744  l_poly_cache = l_poly;
3745  l_qual_cache = MoveMagicVegToFood( l_poly );
3746  }
3747  l_fantastic += l_geo_cache;
3748  l_quality += l_qual_cache;
3749  }
3750  }
3751  m_move_dir_qual[ direction_e ] = l_quality;
3752  if ( m_move_list[ direction_e ] ) {
3753  m_move_list[ direction_e ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3754  }
3755 
3756  // Southeast.
3757  l_quality = 0.0;
3758  l_fantastic = 0;
3760  l_qual_cache = 0.0;
3761  l_poly_cache = -1;
3762 
3763  if ( m_move_allowed[ direction_se ] ) {
3764  for ( int x = a_x + 1, y = a_y + 1; x <= a_x + l_diag_length; x++, y++ ) {
3765  int l_poly = m_map->SupplyPolyRef( x, y );
3766  if ( l_poly != l_poly_cache ) {
3767  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3768  if ( l_geo_cache == -1 ) {
3769  m_move_list[ direction_se ] = 0;
3770  break;
3771  }
3772  l_poly_cache = l_poly;
3773  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3774  }
3775  l_fantastic += l_geo_cache;
3776  l_quality += l_qual_cache;
3777  }
3778  }
3779  m_move_dir_qual[ direction_se ] = l_quality;
3780  if ( m_move_list[ direction_se ] ) {
3781  m_move_list[ direction_se ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3782  }
3783 
3784  // South.
3785  l_quality = 0.0;
3786  l_fantastic = 0;
3787  l_qual_cache = 0.0;
3788  l_poly_cache = -1;
3790 
3791  if ( m_move_allowed[ direction_s ] ) {
3792  for ( int y = a_y + 1; y <= a_y + m_move_step_size; y++ ) {
3793  int l_poly = m_map->SupplyPolyRef( a_x, y );
3794  if ( l_poly != l_poly_cache ) {
3795  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3796  if ( l_geo_cache == -1 ) {
3797  m_move_list[ direction_s ] = 0;
3798  break;
3799  }
3800  l_poly_cache = l_poly;
3801  l_qual_cache = MoveMagicVegToFood( l_poly );
3802  }
3803  l_fantastic += l_geo_cache;
3804  l_quality += l_qual_cache;
3805  }
3806  }
3807  m_move_dir_qual[ direction_s ] = l_quality;
3808  if ( m_move_list[ direction_s ] ) {
3809  m_move_list[ direction_s ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3810  }
3811 
3812  // Southwest.
3813  l_quality = 0.0;
3814  l_fantastic = 0;
3816  l_qual_cache = 0.0;
3817  l_poly_cache = -1;
3818 
3819  if ( m_move_allowed[ direction_sw ] ) {
3820  for ( int x = a_x - 1, y = a_y + 1; x >= a_x - l_diag_length; x--, y++ ) {
3821  int l_poly = m_map->SupplyPolyRef( x, y );
3822  if ( l_poly != l_poly_cache ) {
3823  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3824  if ( l_geo_cache == -1 ) {
3825  m_move_list[ direction_sw ] = 0;
3826  break;
3827  }
3828  l_poly_cache = l_poly;
3829  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3830  }
3831  l_fantastic += l_geo_cache;
3832  l_quality += l_qual_cache;
3833  }
3834  }
3835  m_move_dir_qual[ direction_sw ] = l_quality;
3836  if ( m_move_list[ direction_sw ] ) {
3837  m_move_list[ direction_sw ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3838  }
3839 
3840  // West.
3841  l_quality = 0.0;
3842  l_fantastic = 0;
3844  l_qual_cache = 0.0;
3845  l_poly_cache = -1;
3846 
3847  if ( m_move_allowed[ direction_w ] ) {
3848  for ( int x = a_x - 1; x >= a_x - m_move_step_size; x-- ) {
3849  int l_poly = m_map->SupplyPolyRef( x, a_y );
3850  if ( l_poly != l_poly_cache ) {
3851  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3852  if ( l_geo_cache == -1 ) {
3853  m_move_list[ direction_w ] = 0;
3854  break;
3855  }
3856  l_poly_cache = l_poly;
3857  l_qual_cache = MoveMagicVegToFood( l_poly );
3858  }
3859  l_fantastic += l_geo_cache;
3860  l_quality += l_qual_cache;
3861  }
3862  }
3863  m_move_dir_qual[ direction_w ] = l_quality;
3864  if ( m_move_list[ direction_w ] ) {
3865  m_move_list[ direction_w ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3866  }
3867 
3868  // Northwest.
3869  l_quality = 0.0;
3870  l_fantastic = 0;
3872  l_qual_cache = 0.0;
3873  l_poly_cache = -1;
3874 
3875  if ( m_move_allowed[ direction_nw ] ) {
3876  for ( int y = a_y - 1, x = a_x - 1; y >= a_y - l_diag_length; y--, x-- ) {
3877  int l_poly = m_map->SupplyPolyRef( x, y );
3878  if ( l_poly != l_poly_cache ) {
3879  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3880  if ( l_geo_cache == -1 ) {
3881  m_move_list[ direction_nw ] = 0;
3882  break;
3883  }
3884  l_poly_cache = l_poly;
3885  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3886  }
3887  l_fantastic += l_geo_cache;
3888  l_quality += l_qual_cache;
3889  }
3890  }
3891  m_move_dir_qual[ direction_nw ] = l_quality;
3892  if ( m_move_list[ direction_nw ] ) {
3893  m_move_list[ direction_nw ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3894  }
3895 }
int MoveEvalEdgesAndQual(int a_edges, double a_qual)
Move evaluation taking edges into account.
Definition: Partridge_Covey.cpp:2684
double MoveMagicVegToFood(int a_polygon)
Move optimising food intake.
Definition: Partridge_Covey.cpp:3147

References direction_e, direction_n, direction_ne, direction_nw, direction_s, direction_se, direction_sw, direction_w, m_map, m_move_allowed, m_move_dir_qual, m_move_list, m_move_step_size, MoveCanMove(), MoveEvalEdgesAndQual(), MoveMagicVegToFood(), Landscape::SupplyElementType(), and Landscape::SupplyPolyRef().

Referenced by MoveDistance(), and MoveTo().

◆ MoveOptimalDirectionSlow()

void Partridge_Covey::MoveOptimalDirectionSlow ( int  a_x,
int  a_y 
)
protected

Choose best foraging direction.

Rule: Preferred direction is the one, which gives the best food return.

Sum of distance times 'magic' vegetation2foodvaluepersitance() method.
Each tov type has a constant, which we can use to multiply the insect biomass with (default is now that all are 1.0). We then have to modify this value with some function() of vegetation structure. function() is a precalculated value from 0.0 to 1.0, given as a 4x4 array from vegetation height and biomass.
Also need to ensure the covey moves along the hedges etc.
All this is done whilst checking for wrap-around - therefore SLOW!

3404  {
3414  // The number of steps for a diagonal move is less than step size
3415  // by 1/sqrt(2), as each step is sqrt(2) meters long.
3416  int l_diag_length = ( int )( ( double )m_move_step_size * 0.71 );
3417 
3418  double l_quality = 0.0;
3419  double l_qual_cache = 0.0;
3420  int l_fantastic = 0;
3421  int l_poly_cache = -1;
3422  int l_geo_cache = 0;
3423 
3424  // Current pos to the north (decreasing y).
3425 
3426  // Use current spot in movement list as a temporary flag.
3428 
3429  // Notice: y is allowed to grow negative, this is OK!
3430  // We normalize to the height of the map before using it.
3431  if ( m_move_allowed[ direction_n ] ) {
3432  for ( int y = a_y - 1; y >= a_y - m_move_step_size; y-- ) {
3433  int l_poly = m_map->SupplyPolyRef( a_x, NormDec( y, m_height ) );
3434  if ( l_poly != l_poly_cache ) {
3435  // Crossed into new polygon. Compute new values for
3436  // cache etc.
3437  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3438  if ( l_geo_cache == -1 ) {
3439  // This direction is blocked.
3440  m_move_list[ direction_n ] = 0;
3441  break;
3442  }
3443  l_poly_cache = l_poly;
3444  l_qual_cache = MoveMagicVegToFood( l_poly );
3445  }
3446  }
3447  // Sum up number of especially good edge squares.
3448  l_fantastic += l_geo_cache;
3449  // Sum up food quality.
3450  l_quality += l_qual_cache;
3451  }
3452  m_move_dir_qual[ direction_n ] = l_quality;
3453  if ( m_move_list[ direction_n ] ) {
3454  // This direction isn't blocked, so evaluate and assign
3455  // priority in movement list.
3456  m_move_list[ direction_n ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3457  }
3458 
3459  // Northeast.
3460  l_quality = 0.0;
3461  l_fantastic = 0;
3463  l_qual_cache = 0.0;
3464  l_poly_cache = -1;
3465 
3466  if ( m_move_allowed[ direction_ne ] ) {
3467  for ( int y = a_y - 1, x = a_x + 1; y >= a_y - l_diag_length; y--, x++ ) {
3468  int l_poly = m_map->SupplyPolyRef( NormInc( x, m_width ), NormDec( y, m_height ) );
3469  if ( l_poly != l_poly_cache ) {
3470  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3471  if ( l_geo_cache == -1 ) {
3472  m_move_list[ direction_ne ] = 0;
3473  break;
3474  }
3475  l_poly_cache = l_poly;
3476  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3477  }
3478  l_fantastic += l_geo_cache;
3479  l_quality += l_qual_cache;
3480  }
3481  }
3482  m_move_dir_qual[ direction_ne ] = l_quality;
3483  if ( m_move_list[ direction_ne ] ) {
3484  m_move_list[ direction_ne ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3485  }
3486 
3487  // East.
3488  l_quality = 0.0;
3489  l_fantastic = 0;
3491  l_qual_cache = 0.0;
3492  l_poly_cache = -1;
3493 
3494  if ( m_move_allowed[ direction_e ] ) {
3495  for ( int x = a_x + 1; x <= a_x + m_move_step_size; x++ ) {
3496  int l_poly = m_map->SupplyPolyRef( NormInc( x, m_width ), a_y );
3497  if ( l_poly != l_poly_cache ) {
3498  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3499  if ( l_geo_cache == -1 ) {
3500  m_move_list[ direction_e ] = 0;
3501  break;
3502  }
3503  l_poly_cache = l_poly;
3504  l_qual_cache = MoveMagicVegToFood( l_poly );
3505  }
3506  l_fantastic += l_geo_cache;
3507  l_quality += l_qual_cache;
3508  }
3509  }
3510  m_move_dir_qual[ direction_e ] = l_quality;
3511  if ( m_move_list[ direction_e ] ) {
3512  m_move_list[ direction_e ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3513  }
3514 
3515  // Southeast.
3516  l_quality = 0.0;
3517  l_fantastic = 0;
3519  l_qual_cache = 0.0;
3520  l_poly_cache = -1;
3521 
3522  if ( m_move_allowed[ direction_se ] ) {
3523  for ( int x = a_x + 1, y = a_y + 1; x <= a_x + l_diag_length; x++, y++ ) {
3524  int l_poly = m_map->SupplyPolyRef( NormInc( x, m_width ), NormInc( y, m_height ) );
3525  if ( l_poly != l_poly_cache ) {
3526  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3527  if ( l_geo_cache == -1 ) {
3528  m_move_list[ direction_se ] = 0;
3529  break;
3530  }
3531  l_poly_cache = l_poly;
3532  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3533  }
3534  l_fantastic += l_geo_cache;
3535  l_quality += l_qual_cache;
3536  }
3537  }
3538  m_move_dir_qual[ direction_se ] = l_quality;
3539  if ( m_move_list[ direction_se ] ) {
3540  m_move_list[ direction_se ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3541  }
3542 
3543  // South.
3544  l_quality = 0.0;
3545  l_fantastic = 0;
3546  l_qual_cache = 0.0;
3547  l_poly_cache = -1;
3549 
3550  if ( m_move_allowed[ direction_s ] ) {
3551  for ( int y = a_y + 1; y <= a_y + m_move_step_size; y++ ) {
3552  int l_poly = m_map->SupplyPolyRef( a_x, NormInc( y, m_height ) );
3553  if ( l_poly != l_poly_cache ) {
3554  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3555  if ( l_geo_cache == -1 ) {
3556  m_move_list[ direction_s ] = 0;
3557  break;
3558  }
3559  l_poly_cache = l_poly;
3560  l_qual_cache = MoveMagicVegToFood( l_poly );
3561  }
3562  l_fantastic += l_geo_cache;
3563  l_quality += l_qual_cache;
3564  }
3565  }
3566  m_move_dir_qual[ direction_s ] = l_quality;
3567  if ( m_move_list[ direction_s ] ) {
3568  m_move_list[ direction_s ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3569  }
3570 
3571  // Southwest.
3572  l_quality = 0.0;
3573  l_fantastic = 0;
3575  l_qual_cache = 0.0;
3576  l_poly_cache = -1;
3577 
3578  if ( m_move_allowed[ direction_sw ] ) {
3579  for ( int x = a_x - 1, y = a_y + 1; x >= a_x - l_diag_length; x--, y++ ) {
3580  int l_poly = m_map->SupplyPolyRef( NormDec( x, m_width ), NormInc( y, m_height ) );
3581  if ( l_poly != l_poly_cache ) {
3582  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3583  if ( l_geo_cache == -1 ) {
3584  m_move_list[ direction_sw ] = 0;
3585  break;
3586  }
3587  l_poly_cache = l_poly;
3588  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3589  }
3590  l_fantastic += l_geo_cache;
3591  l_quality += l_qual_cache;
3592  }
3593  }
3594  m_move_dir_qual[ direction_sw ] = l_quality;
3595  if ( m_move_list[ direction_sw ] ) {
3596  m_move_list[ direction_sw ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3597  }
3598 
3599  // West.
3600  l_quality = 0.0;
3601  l_fantastic = 0;
3603  l_qual_cache = 0.0;
3604  l_poly_cache = -1;
3605 
3606  if ( m_move_allowed[ direction_w ] ) {
3607  for ( int x = a_x - 1; x >= a_x - m_move_step_size; x-- ) {
3608  int l_poly = m_map->SupplyPolyRef( NormDec( x, m_width ), a_y );
3609  if ( l_poly != l_poly_cache ) {
3610  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3611  if ( l_geo_cache == -1 ) {
3612  m_move_list[ direction_w ] = 0;
3613  break;
3614  }
3615  l_poly_cache = l_poly;
3616  l_qual_cache = MoveMagicVegToFood( l_poly );
3617  }
3618  l_fantastic += l_geo_cache;
3619  l_quality += l_qual_cache;
3620  }
3621  }
3622  m_move_dir_qual[ direction_w ] = l_quality;
3623  if ( m_move_list[ direction_w ] ) {
3624  m_move_list[ direction_w ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3625  }
3626 
3627  // Northwest.
3628  l_quality = 0.0;
3629  l_fantastic = 0;
3631  l_qual_cache = 0.0;
3632  l_poly_cache = -1;
3633 
3634  if ( m_move_allowed[ direction_nw ] ) {
3635  for ( int y = a_y - 1, x = a_x - 1; y >= a_y - l_diag_length; y--, x-- ) {
3636  int l_poly = m_map->SupplyPolyRef( NormDec( x, m_width ), NormDec( y, m_height ) );
3637  if ( l_poly != l_poly_cache ) {
3638  l_geo_cache = MoveCanMove( m_map->SupplyElementType( l_poly ) );
3639  if ( l_geo_cache == -1 ) {
3640  m_move_list[ direction_nw ] = 0;
3641  break;
3642  }
3643  l_poly_cache = l_poly;
3644  l_qual_cache = MoveMagicVegToFood( l_poly ) * 1.41;
3645  }
3646  l_fantastic += l_geo_cache;
3647  l_quality += l_qual_cache;
3648  }
3649  }
3650  m_move_dir_qual[ direction_nw ] = l_quality;
3651  if ( m_move_list[ direction_nw ] ) {
3652  m_move_list[ direction_nw ] = MoveEvalEdgesAndQual( l_fantastic, l_quality );
3653  }
3654 }
int NormDec(int a_coord, int a_size)
Wrap-around utility function.
Definition: Partridge_Covey.cpp:882
int NormInc(int a_coord, int a_size)
Wrap-around utility function.
Definition: Partridge_Covey.cpp:895

References direction_e, direction_n, direction_ne, direction_nw, direction_s, direction_se, direction_sw, direction_w, m_height, m_map, m_move_allowed, m_move_dir_qual, m_move_list, m_move_step_size, m_width, MoveCanMove(), MoveEvalEdgesAndQual(), MoveMagicVegToFood(), NormDec(), NormInc(), Landscape::SupplyElementType(), and Landscape::SupplyPolyRef().

Referenced by MoveDistance(), and MoveTo().

◆ MoveQualMemory()

void Partridge_Covey::MoveQualMemory ( int  a_qual)
protected

Make a move based on memory of quality.

538  {
539  // Shift down the history array.
540  for ( int i = 0; i < MOVE_QUAL_HIST_SIZE - 1; i++ ) {
541  m_move_qual_hist[ 1 ] [ i ] = m_move_qual_hist[ 1 ] [ i + 1 ];
542  m_move_qual_hist[ 2 ] [ i ] = m_move_qual_hist[ 2 ] [ i + 1 ];
543  m_move_qual_hist[ 3 ] [ i ] = m_move_qual_hist[ 3 ] [ i + 1 ];
544  }
545 
546  // Zero top of history.
547  m_move_qual_hist[ 1 ] [ MOVE_QUAL_HIST_SIZE - 1 ] = 0;
548  m_move_qual_hist[ 2 ] [ MOVE_QUAL_HIST_SIZE - 1 ] = 0;
549  m_move_qual_hist[ 3 ] [ MOVE_QUAL_HIST_SIZE - 1 ] = 0;
550  m_move_qual_memory[ 1 ] = 0;
551  m_move_qual_memory[ 2 ] = 0;
552  m_move_qual_memory[ 3 ] = 0;
553 
554  // Set top of qurrent qual
555  m_move_qual_hist[ a_qual ] [ MOVE_QUAL_HIST_SIZE - 1 ] = 1;
556 
557  // Sum up the array.
558  for ( int i = 0; i < MOVE_QUAL_HIST_SIZE; i++ ) {
559  if ( m_move_qual_hist[ 1 ] [ i ] )
560  m_move_qual_memory[ 1 ] ++;
561  if ( m_move_qual_hist[ 2 ] [ i ] )
562  m_move_qual_memory[ 2 ] ++;
563  if ( m_move_qual_hist[ 3 ] [ i ] )
564  m_move_qual_memory[ 3 ] ++;
565  }
566 }

References m_move_qual_hist, and m_move_qual_memory.

Referenced by MoveDistance(), and MoveTo().

◆ MoveSelect()

int Partridge_Covey::MoveSelect ( void  )
protected

Part of movement evaluation.

These methods:
bool MoveSelectLimit( int a_limit, int a_x, int a_y );
int MoveSelect( void );
void MoveVegConstInit( void );
build a list of possible directions we can move to from our present location, given we are only interested in directions with a quality evaluation equal to a_limit.

330  {
331  int l_rnd;
332  if ( m_move_select_size > 1 )
333  l_rnd = random( m_move_select_size ); else
334  l_rnd = 0;
335 
336 #ifdef PAR_DEBUG
337  printf( "l_rnd : %d\n", l_rnd );
338 #endif
339  return m_move_select_list[ l_rnd ];
340 }
static int m_move_select_size
Definition: Partridge_Covey.cpp:230
static int m_move_select_list[8]
Definition: Partridge_Covey.cpp:229

References m_move_select_list, m_move_select_size, and random().

Referenced by MoveWeighDirection().

◆ MoveSelectFuzzy()

int Partridge_Covey::MoveSelectFuzzy ( void  )
protected

Fuzzdy movement selection.

Select either 1 or -1 or fuzzy chance 0

244  {
245  if ( random( 10000 ) >= cfg_par_move_fuzzy_chance.value() )
246  return 0;
247 
248  if ( random( 100 ) < 50 )
249  return -1;
250 
251  return 1;
252 }
CfgInt cfg_par_move_fuzzy_chance("PAR_MOVE_FUZZY_CHANCE", CFG_CUSTOM, 50)
Chance of imperfect movement decisions.

References cfg_par_move_fuzzy_chance, random(), and CfgInt::value().

Referenced by MoveWeighDirection().

◆ MoveSelectLimit()

bool Partridge_Covey::MoveSelectLimit ( int  a_limit,
int  a_x,
int  a_y 
)
protected

Part of movement evaluation.

These methods:
bool MoveSelectLimit( int a_limit, int a_x, int a_y );
int MoveSelect( void );
void MoveVegConstInit( void );
build a list of possible directions we can move to from our present location, given we are only interested in directions with a quality evaluation equal to a_limit.
Select either 1 or -1 or fuzzy chance 0

261  {
262  bool l_found = false;
263  m_move_select_size = 0;
264 
265  int l_goto = NormInc( m_move_whence_we_came + 4, 8 );
266  int l_goto_sub = NormDec( l_goto - 1, 8 );
267  int l_goto_add = NormInc( l_goto + 1, 8 );
268 
269  if ( m_move_list[ l_goto ] == a_limit ) {
271  l_found = true;
272  }
273  if ( m_move_list[ l_goto_sub ] == a_limit ) {
274  m_move_select_list[ m_move_select_size++ ] = l_goto_sub;
275  l_found = true;
276  }
277  if ( m_move_list[ l_goto_add ] == a_limit ) {
278  m_move_select_list[ m_move_select_size++ ] = l_goto_add;
279  l_found = true;
280  }
281  if ( l_found ) {
282  return true;
283  }
284 
285  l_goto_sub = NormDec( l_goto_sub - 1, 8 );
286  l_goto_add = NormInc( l_goto_add + 1, 8 );
287  if ( m_move_list[ l_goto_sub ] == a_limit ) {
288  m_move_select_list[ m_move_select_size++ ] = l_goto_sub;
289  l_found = true;
290  }
291  if ( m_move_list[ l_goto_add ] == a_limit ) {
292  m_move_select_list[ m_move_select_size++ ] = l_goto_add;
293  l_found = true;
294  }
295  if ( l_found ) {
296  return true;
297  }
298 
299  l_goto_sub = NormDec( l_goto_sub - 1, 8 );
300  l_goto_add = NormInc( l_goto_add + 1, 8 );
301  if ( m_move_list[ l_goto_sub ] == a_limit ) {
302  m_move_select_list[ m_move_select_size++ ] = l_goto_sub;
303  l_found = true;
304  }
305  if ( m_move_list[ l_goto_add ] == a_limit ) {
306  m_move_select_list[ m_move_select_size++ ] = l_goto_add;
307  l_found = true;
308  }
309  if ( l_found ) {
310  return true;
311  }
312 
313  // None of the 7 previous directions matched our current quality
314  // limit. Consider backtracking if our previous quality history
315  // seems reasonable.
316  if ( m_move_list[ m_move_whence_we_came ] == a_limit
319  l_found = true;
320  }
321 
322  return l_found;
323 }
CfgInt cfg_par_movequal_histlimit("PAR_MOVEQUAL_HISTLIMIT", CFG_CUSTOM, 3)
The length of memory for backtracking.

References cfg_par_movequal_histlimit, m_move_list, m_move_qual_memory, m_move_select_list, m_move_select_size, m_move_whence_we_came, NormDec(), NormInc(), and CfgInt::value().

Referenced by MoveWeighDirection().

◆ MoveTo()

void Partridge_Covey::MoveTo ( int  a_x,
int  a_y 
)

unused

570  {
571 
572  m_dist_moved = 0.0;
573  int l_x = m_covey_x;
574  int l_y = m_covey_y;
575 
576  if ( a_step_size != m_move_step_size ) {
577  m_move_step_size = a_step_size;
578  m_move_step_size_inv = 1.0 / ( double )a_step_size;
579  }
580 
581 /*
582  if ( m_move_get_enable ) {
583  m_move_get_index = 0;
584  m_move_get_size = 0;
585  }
586 */
587  while ( m_dist_moved < ( double )a_max_distance ) {
588 
589  // Build list of possible directions, given the location
590  // of the peg.
591  MoveDirectionsAllowed( l_x, l_y );
592 
593 #ifdef PAR_DEBUG
594  printf( "Allowed : %d %d %d %d %d %d %d %d\n", m_move_allowed[ 0 ], m_move_allowed[ 1 ], m_move_allowed[ 2 ],
596 #endif
597 
598  // Build list of movement evaluations in
599  // m_move_list[] from our present location.
600  if ( l_x - a_step_size >= 0 && l_x + a_step_size < m_width && l_y - a_step_size >= 0 && l_y + a_step_size < m_height ) {
601  MoveOptimalDirectionFast( l_x, l_y );
602  } else {
603  MoveOptimalDirectionSlow( l_x, l_y );
604  }
605 
606 #ifdef PAR_DEBUG
607  printf( "DirQual : %d %d %d %d %d %d %d %d\n", m_move_list[ 0 ], m_move_list[ 1 ], m_move_list[ 2 ], m_move_list[ 3 ],
608  m_move_list[ 4 ], m_move_list[ 5 ], m_move_list[ 6 ], m_move_list[ 7 ] );
609 #endif
610 
611  // Take peg location and possibly past history/memory into
612  // account.
613  int l_dir = MoveWeighDirection( l_x, l_y );
614  MoveQualMemory( m_move_list[ l_dir ] );
615 
616 #ifdef PAR_DEBUG
617  printf( "QualMemo: 1: %d 2: %d 3: %d\n", m_move_qual_memory[ 1 ], m_move_qual_memory[ 2 ], m_move_qual_memory[ 3 ] );
618  printf( "Selected: %d\n", l_dir );
619 #endif
620  m_move_whence_we_came = Norm( l_dir - 4, 8 );
621 
622  // We now have the direction that we want to move in l_dir.
623  m_food_today += m_move_dir_qual[ l_dir ];
624 
625  // This call also updates l_x and l_y. Nasty, nasty. ;-)
626  m_dist_moved += MoveDoIt( & l_x, & l_y, l_dir, a_step_size );
627 #ifdef PAR_DEBUG
628  //printf("Dist Sum: %f\n", m_dist_moved );
629  printf( "Coords : %d %d\n\n", l_x, l_y );
630 #endif
631 
632  // Collect movement reports.
633  /*
634  if ( m_move_get_enable ) {
635  m_move_get_size++;
636  m_move_get_x.resize( m_move_get_size );
637  m_move_get_y.resize( m_move_get_size );
638  m_move_get_x[ m_move_get_index ] = l_x;
639  m_move_get_y[ m_move_get_index ] = l_y;
640  m_move_get_index++;
641  }
642  */
643 }
644 
645  CoveyUpdateMemberPositions( l_x, l_y );
646  m_move_get_index = 0;
647  m_covey_x = l_x;
648  m_covey_y = l_y;
649  m_assess_done = false;
650 }

References CoveyUpdateMemberPositions(), m_assess_done, m_covey_x, m_covey_y, m_dist_moved, m_food_today, m_height, m_move_allowed, m_move_dir_qual, m_move_get_index, m_move_list, m_move_qual_memory, m_move_step_size, m_move_step_size_inv, m_move_whence_we_came, MoveDirectionsAllowed(), MoveDoIt(), MoveOptimalDirectionFast(), MoveOptimalDirectionSlow(), MoveQualMemory(), MoveWeighDirection(), and Norm().

◆ MoveTryExclude()

bool Partridge_Covey::MoveTryExclude ( int  a_dist_sq)
protected

Uses the peg force to exclude possible movement directions.

MoveTryExclude() should return a boolean distribution depending on the squared distance from the current location and the covey 'peg'. It is used when determining which directions we are allowed in, given the current location, and is called on for quadrants 'perpendicular' to the direction of the peg. Ie. moves toward the peg are always allowed, perpendicular is determined by this method, and those away by Partridge_Covey::MoveTryExcludeHarder().
If both methods always return true for distances below a certain threshold, the covey is allowed to roam freely within a circle of sqrt(threshold).
Note that in these methods a_dist_sq is treated linearly, meaning that the 'force' against moves away from the peg will automatically be a second order polynomial.
The implementation of these methods are currently quite rudimentary. One might want to incorporate such variables as the age of the chicks, size of the territory etc.

2735  {
2736  // Half Radius Squared
2737  int l_hrs = ( int )m_nearest_covey_dist >> 1;
2738  l_hrs = l_hrs * l_hrs;
2739  if ( a_dist_sq < l_hrs || ( random( 100 ) < 50 ) )
2740  return true;
2741 
2742  return false;
2743 }

References m_nearest_covey_dist, and random().

Referenced by MoveDirectionsAllowed().

◆ MoveTryExcludeHarder()

bool Partridge_Covey::MoveTryExcludeHarder ( int  a_dist_sq)
protected

Uses the peg force to exclude possible movement directions.

Called for quadrants facing away from the peg - see Partridge_Covey::MoveTryExclude

2750  {
2751  // Half Radius Squared
2752  int l_hrs = ( int )m_nearest_covey_dist >> 1;
2753  l_hrs = l_hrs * l_hrs;
2754  if ( a_dist_sq < l_hrs )
2755  return true;
2756 
2757  if ( a_dist_sq < l_hrs * 1.6 && random( 100 ) < 10 )
2758  return true;
2759 
2760  return false;
2761 }

References m_nearest_covey_dist, and random().

Referenced by MoveDirectionsAllowed().

◆ MoveVegConstInit()

void Partridge_Covey::MoveVegConstInit ( void  )
protected

Part of movement evaluation.

These methods:
bool MoveSelectLimit( int a_limit, int a_x, int a_y );
int MoveSelect( void );
void MoveVegConstInit( void );
build a list of possible directions we can move to from our present location, given we are only interested in directions with a quality evaluation equal to a_limit.
This was intended to be used to modify movement characteristics dependent on vegetation type, but lacking data all values are set to 1.0.

3304  {
3306  return;
3308 
3318  m_move_veg_const[tov_Maize] = 1.0;
3322  m_move_veg_const[tov_None] = 1.0;
3323  m_move_veg_const[tov_Oats] = 1.0;
3324 
3325  // 10
3338 
3339  // 20
3340  m_move_veg_const[tov_OOats] = 1.0;
3350 
3351  // 30
3364 
3365  // 40
3377 
3378  // 50
3394  m_move_veg_const[tov_Heath] = 1.0;
3395 
3396  // Must be here. tov_Undefined is returned by polygons
3397  // without growth.
3399 }
double m_move_veg_const[]
Definition: Partridge_Covey.cpp:223
static bool m_move_veg_const_init_done
Definition: Partridge_Covey.cpp:3299

References m_move_veg_const, m_move_veg_const_init_done, tov_AgroChemIndustryCereal, tov_BroadBeans, tov_Carrots, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_FieldPeas, tov_FodderBeet, tov_FodderGrass, tov_Heath, tov_Maize, tov_MaizeSilage, tov_NaturalGrass, tov_NoGrowth, tov_None, tov_Oats, tov_OBarleyPeaCloverGrass, tov_OCarrots, tov_OCloverGrassGrazed1, tov_OCloverGrassGrazed2, tov_OCloverGrassSilage1, tov_OFieldPeas, tov_OFieldPeasSilage, tov_OFirstYearDanger, tov_OFodderBeet, tov_OGrazingPigs, tov_OMaizeSilage, tov_OOats, tov_OPermanentGrassGrazed, tov_OPotatoes, tov_OSBarleySilage, tov_OSeedGrass1, tov_OSeedGrass2, tov_OSetaside, tov_OSpringBarley, tov_OSpringBarleyClover, tov_OSpringBarleyExt, tov_OSpringBarleyGrass, tov_OSpringBarleyPigs, tov_OTriticale, tov_OWinterBarley, tov_OWinterRape, tov_OWinterRye, tov_OWinterWheat, tov_OWinterWheatUndersown, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_Potatoes, tov_PotatoesIndustry, tov_SeedGrass1, tov_SeedGrass2, tov_Setaside, tov_SpringBarley, tov_SpringBarleyCloverGrass, tov_SpringBarleyGrass, tov_SpringBarleyPTreatment, tov_SpringBarleySeed, tov_SpringBarleySilage, tov_SpringBarleySKManagement, tov_SpringBarleySpr, tov_SpringRape, tov_SpringWheat, tov_SugarBeet, tov_Triticale, tov_Undefined, tov_WinterBarley, tov_WinterRape, tov_WinterRye, tov_WinterWheat, tov_WinterWheatShort, tov_WWheatPControl, tov_WWheatPToxicControl, and tov_WWheatPTreatment.

Referenced by Partridge_Covey().

◆ MoveWeighDirection()

int Partridge_Covey::MoveWeighDirection ( int  a_x,
int  a_y 
)
protected

Weighted foraging walk.

Given our current location and m_move_list[], decide the direction to go next.
Do this by:
A) Remove directions from whence we came by calling Partridge_Coveh::MoveExcludedByPast()
B) Build list of possible move directions at a given limit (3 == best moves etc.)
C) Of those directions in the temporary select list, choose the previous direction we went to, or, if not present, a random direction.
D) If no valid directions could be found even at limit 1, try backtracking down the patch from where we came.
E) Try to fuzzy move from the choosen path (if not blocked).

344  {
345  int l_dir = -1;
346  bool loop=false; // This is only needed to stop compiler warnings
347  // The next section of code finds a direction with the best quality, medium then worst, then gives up if nothing
348  do { // This loop does not do anything except it prevents the MoveSelectLimit from being called unnecessarily
349  if ( MoveSelectLimit( 3, a_x, a_y ) ) {
350  l_dir = MoveSelect();
351  break;
352  }
353 
354  if ( MoveSelectLimit( 2, a_x, a_y ) ) {
355  l_dir = MoveSelect();
356  break;
357  }
358 
359  if ( MoveSelectLimit( 1, a_x, a_y ) ) {
360  l_dir = MoveSelect();
361  }
362  } while ( loop );
363 
364 #ifdef PAR_DEBUG
365  printf( "Select : %d %d %d %d %d %d %d %d :: %d\n", m_move_select_list[ 0 ], m_move_select_list[ 1 ],
368 
369 #endif
370 
371  // If we couldn't find an useful direction so far, then
372  // we just have to backtrack down the path from which we came.
373  // Do try to sidestep just a little in a random direction though.
374  if ( l_dir == -1 ) {
375  if ( random( 100 ) < 50 ) {
376  if ( m_move_list[ NormDec( m_move_whence_we_came - 1, 8 ) ] > 0 )
377  l_dir = NormDec( m_move_whence_we_came - 1, 8 ); else if ( m_move_list[ NormInc( m_move_whence_we_came + 1, 8 ) ] > 0 )
378  l_dir = NormInc( m_move_whence_we_came + 1, 8 ); else
379  l_dir = m_move_whence_we_came;
380  } else {
381  if ( m_move_list[ NormInc( m_move_whence_we_came + 1, 8 ) ] > 0 )
382  l_dir = NormInc( m_move_whence_we_came + 1, 8 ); else if ( m_move_list[ NormDec( m_move_whence_we_came - 1, 8 ) ] > 0 )
383  l_dir = NormDec( m_move_whence_we_came - 1, 8 ); else
384  l_dir = m_move_whence_we_came;
385  }
386  }
387  // Move fuzzy if allowed to do so.
388  int l_fuzzy = Norm( l_dir + MoveSelectFuzzy(), 8 );
389  if ( m_move_list[ l_fuzzy ] > 0 )
390  return l_fuzzy;
391 
392  return l_dir;
393 }
int MoveSelect(void)
Part of movement evaluation.
Definition: Partridge_Covey.cpp:330
bool MoveSelectLimit(int a_limit, int a_x, int a_y)
Part of movement evaluation.
Definition: Partridge_Covey.cpp:261
int MoveSelectFuzzy(void)
Fuzzdy movement selection.
Definition: Partridge_Covey.cpp:244

References m_move_list, m_move_select_list, m_move_select_size, m_move_whence_we_came, MoveSelect(), MoveSelectFuzzy(), MoveSelectLimit(), Norm(), NormDec(), NormInc(), and random().

Referenced by MoveDistance(), and MoveTo().

◆ NestBadArea()

bool Partridge_Covey::NestBadArea ( int  a_x,
int  a__y 
)
protected

Nest location evaluation function.

2947  {
2948  TTypesOfLandscapeElement l_cet = m_map->SupplyElementType( a_x, a_y );
2949 
2950  switch ( l_cet ) {
2951  case tole_PermPasture:
2952  case tole_Scrub:
2953  case tole_RiversidePlants:
2954  case tole_RiversideTrees:
2955  case tole_DeciduousForest:
2956  case tole_MixedForest:
2957  case tole_ConiferousForest:
2958  case tole_StoneWall:
2959  case tole_Fence:
2960  case tole_Track:
2961  case tole_SmallRoad:
2962  case tole_LargeRoad:
2963  case tole_ActivePit:
2964  case tole_Hedges:
2965  case tole_Marsh:
2966  case tole_PitDisused:
2967  case tole_RoadsideVerge:
2968  case tole_Railway:
2969  case tole_FieldBoundary:
2973  case tole_NaturalGrassDry:
2974  case tole_Heath:
2975  case tole_Orchard:
2976  case tole_YoungForest:
2977  case tole_HedgeBank:
2978  case tole_BeetleBank:
2980  case tole_Field:
2981  case tole_OrchardBand:
2982  case tole_MownGrass:
2983  case tole_NaturalGrassWet:
2984  case tole_RoadsideSlope:
2985  case tole_Vildtager:
2986  return false;
2987 
2988  case tole_MetalledPath:
2989  case tole_Carpark:
2990  case tole_Churchyard:
2991  case tole_Saltmarsh:
2992  case tole_Stream:
2993  case tole_HeritageSite:
2994  case tole_Garden:
2995  case tole_Building:
2996  case tole_Pond:
2997  case tole_Freshwater:
2998  case tole_River:
2999  case tole_Saltwater:
3000  case tole_Coast:
3001  case tole_BareRock:
3002  case tole_AmenityGrass:
3003  case tole_Parkland:
3004  case tole_UrbanNoVeg:
3005  case tole_UrbanPark:
3007  case tole_SandDune:
3008  case tole_Copse:
3009  case tole_IndividualTree:
3010  case tole_PlantNursery:
3011  case tole_WindTurbine:
3012  case tole_WoodyEnergyCrop:
3013  case tole_WoodlandMargin:
3014  case tole_Pylon:
3015  return true;
3016 
3017  default:
3018  g_msg->Warn( WARN_BUG, "Partridge_Covey::NestBadArea(): Unknown tole type", "" );
3019  exit( 1 );
3020  }
3021 }

References g_msg, m_map, Landscape::SupplyElementType(), tole_ActivePit, tole_AmenityGrass, tole_BareRock, tole_BeetleBank, tole_Building, tole_BuiltUpWithParkland, tole_Carpark, tole_Churchyard, tole_Coast, tole_ConiferousForest, tole_Copse, tole_DeciduousForest, tole_Fence, tole_Field, tole_FieldBoundary, tole_Freshwater, tole_Garden, tole_Heath, tole_HedgeBank, tole_Hedges, tole_HeritageSite, tole_IndividualTree, tole_LargeRoad, tole_Marsh, tole_MetalledPath, tole_MixedForest, tole_MownGrass, tole_NaturalGrassDry, tole_NaturalGrassWet, tole_Orchard, tole_OrchardBand, tole_Parkland, tole_PermanentSetaside, tole_PermPasture, tole_PermPastureLowYield, tole_PermPastureTussocky, tole_PitDisused, tole_PlantNursery, tole_Pond, tole_Pylon, tole_Railway, tole_River, tole_RiversidePlants, tole_RiversideTrees, tole_RoadsideSlope, tole_RoadsideVerge, tole_Saltmarsh, tole_Saltwater, tole_SandDune, tole_Scrub, tole_SmallRoad, tole_StoneWall, tole_Stream, tole_Track, tole_UnsprayedFieldMargin, tole_UrbanNoVeg, tole_UrbanPark, tole_Vildtager, tole_WindTurbine, tole_WoodlandMargin, tole_WoodyEnergyCrop, tole_YoungForest, MapErrorMsg::Warn(), and WARN_BUG.

Referenced by NestBadAreasScanFast(), and NestBadAreasScanSlow().

◆ NestBadAreasScanFast()

bool Partridge_Covey::NestBadAreasScanFast ( int  a_min_x,
int  a_min_y,
int  a_length,
int  a_x,
int  a_y 
)
protected

Nest location evaluation function.

1170  {
1171  for ( int i = 0; i < a_length; i++ ) {
1172  int x_inc = a_min_x + i;
1173  int y_inc = a_min_y + i;
1174  if ( NestBadArea( x_inc, y_inc ) || NestBadArea( x_inc, a_min_y + a_length - i ) || NestBadArea( x_inc, a_y )
1175  || NestBadArea( a_x, y_inc ) ) {
1176  return true;
1177  }
1178  }
1179 
1180  return false;
1181 }
bool NestBadArea(int a_x, int a__y)
Nest location evaluation function.
Definition: Partridge_Covey.cpp:2947

References NestBadArea().

Referenced by NestNearBadAreas().

◆ NestBadAreasScanSlow()

bool Partridge_Covey::NestBadAreasScanSlow ( int  a_min_x,
int  a_min_y,
int  a_length,
int  a_x,
int  a_y 
)
protected

Nest location evaluation function.

1150  {
1151  int y_dec_base = NormInc( a_min_y + a_length, m_height );
1152 
1153  for ( int i = 0; i < a_length; i++ ) {
1154  int x_inc = Norm( a_min_x + i, m_width );
1155  int y_inc = Norm( a_min_y + i, m_height );
1156  int y_dec = Norm( y_dec_base - i, m_height );
1157  if ( NestBadArea( x_inc, y_inc ) || NestBadArea( x_inc, y_dec ) || NestBadArea( x_inc, a_y )
1158  || NestBadArea( a_x, y_inc ) ) {
1159  return true;
1160  }
1161  }
1162 
1163  return false;
1164 }

References m_height, m_width, NestBadArea(), Norm(), and NormInc().

Referenced by NestNearBadAreas().

◆ NestFindFast()

bool Partridge_Covey::NestFindFast ( int  a_min_x_incl,
int  a_max_x_excl,
int  a_min_y_incl,
int  a_max_y_excl 
)
protected

Find nest location.

1207  {
1208  int l_poly_cache = -1;
1210  for ( int loops = 0; loops < 10; loops++ ) {
1211  // Allows us 10 goes at finding a site
1212  for ( int x = a_min_x_incl; x < a_max_x_excl; x++ ) {
1213  for ( int y = a_min_y_incl; y < a_max_y_excl; y++ ) {
1214  int l_poly = m_map->SupplyPolyRef( x, y );
1215  if ( l_poly == l_poly_cache )
1216  continue;
1217 
1218  l_poly_cache = l_poly;
1219 
1220  if ( NestGoodSpot( x, y ) && !NestNearBadAreas( x, y ) && !NestNearNests( x, y, l_min_dist_sq ) ) {
1222  m_nest_on_nest = true;
1223  return true;
1224  }
1225  }
1226  }
1227  a_min_x_incl++;
1228  a_max_x_excl--;
1229  a_min_y_incl++;
1230  a_max_y_excl--;
1231  }
1232  return false;
1233 }
CfgInt g_par_nest_min_dist_other_nest("PAR_NEST_MIN_DIST_OTHER_NEST", CFG_CUSTOM, 50)
Minimum nest distance to other nests.
bool NestNearBadAreas(int a_x, int a__y)
Test for proximity to unacceptable areas.
Definition: Partridge_Covey.cpp:1131
bool NestGoodSpot(int a_x, int a_y)
Evaluate x,y as a nest location.
Definition: Partridge_Covey.cpp:2876
bool NestNearNests(int a_x, int a_y, int a_min_dist_sq)
Nest location evaluation function.
Definition: Partridge_Covey.cpp:1188

References CoveyUpdateMemberPositions(), g_par_nest_min_dist_other_nest, m_map, m_nest_on_nest, NestGoodSpot(), NestNearBadAreas(), NestNearNests(), Landscape::SupplyPolyRef(), and CfgInt::value().

Referenced by NestFindLocation().

◆ NestFindLocation()

bool Partridge_Covey::NestFindLocation ( void  )

Try to locate a suitable nesting location.

Update covey position if we can find a suitable location and return true, or false if we failed to find a good spot.

1107  {
1108  // This algorithm can definitely be improved, time permitting!
1109  // FN, 16/6-2003.
1110 
1111  int l_whh = ( ( int )m_nearest_covey_dist ) >> 1;
1112  if ( g_par_terr_max_width.value() < l_whh ) {
1113  l_whh = g_par_terr_max_width.value();
1114  }
1115 
1116  int l_min_x_incl = m_center_x - l_whh;
1117  int l_max_x_excl = m_center_x + l_whh;
1118  int l_min_y_incl = m_center_y - l_whh;
1119  int l_max_y_excl = m_center_y + l_whh;
1120 
1121  if ( l_min_x_incl < 0 || l_max_x_excl > m_width || l_min_y_incl < 0 || l_max_y_excl > m_height ) {
1122  return NestFindSlow( l_min_x_incl, l_max_x_excl, l_min_y_incl, l_max_y_excl );
1123  }
1124 
1125  return NestFindFast( l_min_x_incl, l_max_x_excl, l_min_y_incl, l_max_y_excl );
1126 }
bool NestFindSlow(int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
Find nest location (wrap around)
Definition: Partridge_Covey.cpp:1236
bool NestFindFast(int a_min_x_incl, int a_max_x_excl, int a_min_y_incl, int a_max_y_excl)
Find nest location.
Definition: Partridge_Covey.cpp:1207

References g_par_terr_max_width, m_center_x, m_center_y, m_height, m_nearest_covey_dist, m_width, NestFindFast(), NestFindSlow(), and CfgInt::value().

Referenced by Partridge_Female::FMakingNest().

◆ NestFindSlow()

bool Partridge_Covey::NestFindSlow ( int  a_min_x_incl,
int  a_max_x_excl,
int  a_min_y_incl,
int  a_max_y_excl 
)

Find nest location (wrap around)

1236  {
1237  int l_poly_cache = -1;
1239 
1240  ForIterator * l_fx = new ForIterator( a_min_x_incl, a_max_x_excl, 1, 0, m_width );
1241  int * l_lx = l_fx->GetList(